mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
22 lines
449 B
TypeScript
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;
|
|
}
|