@selfcommunity/react-core
Version:
React Core Components useful for integrating UI Community components (react-ui).
27 lines (26 loc) • 838 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
/**
* If for some reason you can't cleanup or clear the timeouts properly,
* you can use the following hook to verify just before setting state
* if the component is still mounted.
* Usage:
* import {useIsComponentMountedRef} from '@selfcommunity/react-core';
*
* const MyComponent = () => {
* const isMountedRef = useIsComponentMountedRef();
* // ex: isMountedRef.current && setState(...)
* };
*/
const useIsComponentMountedRef = () => {
const isMounted = (0, react_1.useRef)(false);
(0, react_1.useEffect)(() => {
isMounted.current = true;
return () => {
isMounted.current = false;
};
}, []);
return isMounted;
};
exports.default = useIsComponentMountedRef;
;