16 lines
343 B
TypeScript
16 lines
343 B
TypeScript
|
|
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;
|
||
|
|
};
|