Created
March 30, 2020 20:54
-
-
Save garmjs/fc20790caf10b507d9acfead154a327e to your computer and use it in GitHub Desktop.
Gatsby client side only
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
import React from "react" | |
function ClientOnly({ children, ...delegated }) { | |
const [hasMounted, setHasMounted] = React.useState(false) | |
React.useEffect(() => { | |
setHasMounted(true) | |
}, []) | |
if (!hasMounted) { | |
return null | |
} | |
return <div {...delegated}>{children}</div> | |
} | |
export default ClientOnly |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment