Skip to content

Instantly share code, notes, and snippets.

@soker90
Created August 30, 2020 18:32
Show Gist options
  • Save soker90/04a97b174d97bd9c154812e015f223c3 to your computer and use it in GitHub Desktop.
Save soker90/04a97b174d97bd9c154812e015f223c3 to your computer and use it in GitHub Desktop.
Hook for useEffect dependecy
import { useRef, useEffect } from 'react';
const useIsMountedRef = () => {
const isMounted = useRef(true);
useEffect(() => () => {
isMounted.current = false;
}, []);
return isMounted;
}
export default useIsMountedRef;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment