Files
2024-02-15 17:01:50 +00:00

22 lines
449 B
TypeScript

import {useEffect, useRef} from 'react';
/**
* Returns a ref that captures the current mounted state of the component
*
* This hook is handy for the cases when you have to detect component mount state
* within async effects.
*/
export function useIsMountedRef() {
const isMounted = useRef(false);
useEffect(() => {
isMounted.current = true;
return () => {
isMounted.current = false;
};
}, []);
return isMounted;
}