mirror of
https://github.com/documenso/documenso.git
synced 2026-07-25 17:35:05 +10:00
chore: cleanup useEffect
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useSyncExternalStore } from 'react';
|
||||
|
||||
export const ClientOnly = async ({ children }: { children: React.ReactNode }) => {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
return mounted ? children : null;
|
||||
const subscribe = () => {
|
||||
return () => {};
|
||||
};
|
||||
|
||||
const getSnapshot = () => {
|
||||
return true;
|
||||
};
|
||||
|
||||
const getServerSnapshot = () => {
|
||||
return false;
|
||||
};
|
||||
|
||||
export const ClientOnly = ({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}): React.ReactElement | null => {
|
||||
const isClient = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
||||
|
||||
return isClient ? <>{children}</> : null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user