mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
22 lines
480 B
TypeScript
22 lines
480 B
TypeScript
import { useSyncExternalStore, type ReactNode } from 'react';
|
|
|
|
interface ClientOnlyProps {
|
|
children: () => ReactNode;
|
|
fallback?: ReactNode;
|
|
}
|
|
|
|
const noop = () => undefined;
|
|
const emptySubscribe = () => noop;
|
|
|
|
const ClientOnly = ({ children, fallback = null }: ClientOnlyProps) => {
|
|
const mounted = useSyncExternalStore(
|
|
emptySubscribe,
|
|
() => true,
|
|
() => false,
|
|
);
|
|
|
|
return mounted ? children() : fallback;
|
|
};
|
|
|
|
export default ClientOnly;
|