Files
cinny/src/app/hooks/useAlive.ts
T

16 lines
343 B
TypeScript
Raw Normal View History

2023-06-12 21:15:23 +10:00
import { useCallback, useEffect, useRef } from 'react';
export const useAlive = (): (() => boolean) => {
const aliveRef = useRef<boolean>(true);
useEffect(() => {
aliveRef.current = true;
return () => {
aliveRef.current = false;
};
}, []);
const alive = useCallback(() => aliveRef.current, []);
return alive;
};