Skip to content

Instantly share code, notes, and snippets.

@garmjs
Created March 30, 2020 20:54
Show Gist options
  • Save garmjs/fc20790caf10b507d9acfead154a327e to your computer and use it in GitHub Desktop.
Save garmjs/fc20790caf10b507d9acfead154a327e to your computer and use it in GitHub Desktop.
Gatsby client side only
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