Last active
September 3, 2025 15:18
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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