urbit/pkg/interface/webterm/lib/useIsMounted.ts
2022-07-17 15:16:35 +02:00

18 lines
323 B
TypeScript

import { useCallback, useEffect, useRef } from 'react';
function useIsMounted() {
const isMounted = useRef(false);
useEffect(() => {
isMounted.current = true;
return () => {
isMounted.current = false;
};
}, []);
return useCallback(() => isMounted.current, []);
}
export default useIsMounted;