@mirawision/reactive-hooks
Version:
A comprehensive collection of 50+ React hooks for state management, UI interactions, device APIs, async operations, drag & drop, audio/speech, and more. Full TypeScript support with SSR safety.
19 lines (18 loc) • 635 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useIsMounted = useIsMounted;
const react_1 = require("react");
/**
* Hook that tracks whether a component is mounted
* Useful for preventing state updates on unmounted components
*
* @returns A function that returns true if the component is still mounted
*/
function useIsMounted() {
const isMountedRef = (0, react_1.useRef)(true);
const isMounted = (0, react_1.useCallback)(() => isMountedRef.current, []);
(0, react_1.useEffect)(() => {
return () => void (isMountedRef.current = false);
}, []);
return isMounted;
}