import { useHistory, useLocation } from 'react-router-dom';
export const useSetLocationState = () => {
    const history = useHistory();
    const location = useLocation();
    const setLocationState = (newState) => {
        const currentState = location.state || {};
        // Avoid unnecessary replace if state is already the same
        const hasChanged = Object.entries(newState).some(([key, value]) => currentState[key] !== value);
        if (!hasChanged || !!(location === null || location === void 0 ? void 0 : location.state))
            return;
        history.replace({
            pathname: location.pathname,
            search: location.search,
            hash: location.hash,
            state: Object.assign(Object.assign({}, currentState), newState)
        });
    };
    return setLocationState;
};
//# sourceMappingURL=useSetLocationState.js.map