Last active
August 8, 2021 11:14
-
-
Save LouisPetrik/b1323bd07b455168dcb51b865e1407b4 to your computer and use it in GitHub Desktop.
A custom hook for checking if a component already had it's initial render. Useful for building a hook-based componentDidUpdate() alternative.
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 { useEffect, useRef } from 'react' | |
export const useDidMount = () => { | |
const didMountRef = useRef(false) | |
useEffect(() => { | |
didMountRef.current = true | |
}, []) | |
return didMountRef.current | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment