Last active
April 20, 2020 16:43
-
-
Save garmjs/4bfd56ee393ed85f7193e61a45dd51de to your computer and use it in GitHub Desktop.
Gatsby client only | This is helpful if the component you where trying to use doesn't support SSR
This file contains 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