Skip to content

Instantly share code, notes, and snippets.

@jul-sh
Last active February 9, 2019 18:52
Show Gist options
  • Save jul-sh/efde18802f1769a50566d2e434bb91e0 to your computer and use it in GitHub Desktop.
Save jul-sh/efde18802f1769a50566d2e434bb91e0 to your computer and use it in GitHub Desktop.
import { useState, useEffect } from 'react'
// Use this hook to quickly read whether a component is being rendered server
// side or client-side. This can be helpful when building components that are
// intended to work without client-side JavaScript.
// Use like:
// const isMounted = useIsMounted()
const useIsMounted = () => {
const [ isMounted, setIsMounted ] = useState(false)
useEffect(() => setIsMounted(true), [])
return isMounted
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment