mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-02-24 22:23:06 +01:00
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;
|
||
|
};
|