UNPKG

wix-style-react

Version:
18 lines (14 loc) 427 B
import { useRef, useEffect } from 'react'; // Returns a function that checks whether component is still mounted const useIsMounted = () => { const mountedRef = useRef(true); useEffect(() => { // React performs the cleanup when the component unmounts const cleanup = () => { mountedRef.current = false; }; return cleanup; }, []); return () => mountedRef.current; }; export default useIsMounted;