"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useStateSafely = void 0;
const react_1 = require("react");
const useStateSafely = (initialState) => {
    const mountedRef = (0, react_1.useRef)(false);
    (0, react_1.useEffect)(() => {
        mountedRef.current = true;
        return () => {
            mountedRef.current = false;
        };
    }, []);
    const [state, setState] = (0, react_1.useState)(initialState);
    const setStateSafely = (0, react_1.useCallback)((arg) => {
        if (mountedRef.current) {
            setState(arg);
        }
    }, []);
    return [state, setStateSafely];
};
exports.useStateSafely = useStateSafely;
exports.default = exports.useStateSafely;
//# sourceMappingURL=useStateSafely.js.map