Last active
February 9, 2019 18:52
-
-
Save jul-sh/efde18802f1769a50566d2e434bb91e0 to your computer and use it in GitHub Desktop.
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 { 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