chore: cleanup useEffect

This commit is contained in:
Ephraim Atta-Duncan
2025-08-21 21:58:14 +00:00
parent 231ef9c27e
commit db4d33d039
55 changed files with 637 additions and 643 deletions
+21 -9
View File
@@ -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;
};