wix-style-react
Version:
27 lines (22 loc) • 634 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = require("react");
// Returns a function that checks whether component is still mounted
var useIsMounted = function useIsMounted() {
var mountedRef = (0, _react.useRef)(true);
(0, _react.useEffect)(function () {
// React performs the cleanup when the component unmounts
var cleanup = function cleanup() {
mountedRef.current = false;
};
return cleanup;
}, []);
return function () {
return mountedRef.current;
};
};
var _default = useIsMounted;
exports["default"] = _default;