Skip to content

Instantly share code, notes, and snippets.

@simbathesailor
Last active February 2, 2020 08:36
Show Gist options
  • Save simbathesailor/2e6a17f1f9423b058e0e006e8e8a88be to your computer and use it in GitHub Desktop.
Save simbathesailor/2e6a17f1f9423b058e0e006e8e8a88be to your computer and use it in GitHub Desktop.
useIsMountedRef.jsx
const useIsMountedRef = () => {
const isMounted = React.useRef(false);
React.useEffect(() => {
isMounted.current = true;
return () => (isMounted.current = false);
}, []);
return isMounted;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment