mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 01:54:43 +00:00
Add leaflet-powered brewery map
This commit is contained in:
21
web/frontend/app/components/ClientOnly.tsx
Normal file
21
web/frontend/app/components/ClientOnly.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user