Skip to content

Instantly share code, notes, and snippets.

@nirajgiriXD
Last active September 3, 2025 15:18
Show Gist options
  • Save nirajgiriXD/e6a4c72c7911e52841d1eb3b487908f8 to your computer and use it in GitHub Desktop.
Save nirajgiriXD/e6a4c72c7911e52841d1eb3b487908f8 to your computer and use it in GitHub Desktop.
A React component that renders its children only on the client to prevent SSR hydration issues.
export const ClientOnly = ({ children }) => {
const [hasMounted, setHasMounted] = useState(false);
useEffect(() => setHasMounted(true), []);
if (!hasMounted) return null;
return <>{children}</>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment