mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
17 lines
354 B
TypeScript
17 lines
354 B
TypeScript
import { useCallback, useEffect, useRef } from 'react';
|
|
|
|
export default function useMountedState(): () => boolean {
|
|
const mountedRef = useRef<boolean>(false);
|
|
const get = useCallback(() => mountedRef.current, []);
|
|
|
|
useEffect(() => {
|
|
mountedRef.current = true;
|
|
|
|
return () => {
|
|
mountedRef.current = false;
|
|
};
|
|
});
|
|
|
|
return get;
|
|
}
|