Skip to content

Instantly share code, notes, and snippets.

@SeedyROM
Created September 29, 2019 09:31
Show Gist options
  • Save SeedyROM/3a82ff04b3f3a441fcd12ade16dd1bc0 to your computer and use it in GitHub Desktop.
Save SeedyROM/3a82ff04b3f3a441fcd12ade16dd1bc0 to your computer and use it in GitHub Desktop.
React hook to handle if an effect updated.
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