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.

Revisions

  1. garmjs created this gist Mar 30, 2020.
    14 changes: 14 additions & 0 deletions gatsby.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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