Created
September 29, 2019 09:31
-
-
Save SeedyROM/3a82ff04b3f3a441fcd12ade16dd1bc0 to your computer and use it in GitHub Desktop.
React hook to handle if an effect updated.
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
const useDidUpdate = () => { | |
const isNotMounted = useRef(true); | |
useEffect(() => { | |
if (isNotMounted.current) { | |
isNotMounted.current = false; | |
} | |
}); | |
return !isNotMounted.current; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment