Skip to content

Instantly share code, notes, and snippets.

@garmjs
Last active April 20, 2020 16:43
Show Gist options
  • Save garmjs/4bfd56ee393ed85f7193e61a45dd51de to your computer and use it in GitHub Desktop.
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
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