Closed maciossek closed 7 months ago
state
is one of the options of setLocation
so you have to proxy the second argument (or better, rest of args):
const useLocationWithConfirmation = (...args) => {
const historyState = useHistoryState();
const [location, setLocation] = useBrowserLocation(...args);
const ctx = useContext(LockContext);
console.log(history.state, historyState);
return [
location,
(newLocation, ...options) => {
let perfomNavigation = true;
if (ctx.lock) {
perfomNavigation = window.confirm(ctx.message || "Are you sure?");
}
if (perfomNavigation) setLocation(newLocation, ...options);
},
];
};
Wonderful, I totally missed that. Many thanks for the super quick reply! Also a big thank you for writing the lib!
Hello there!
I am struggling to understand where the history state get's "swallowed" when having a custom hook. I forked the initial example and updated the dependencies. Currently logging the
history.state
or theuseHistoryState()
and sadly beingnull
when using the custom hook. It works as intended when I remove the custom hook.This is related to #39.
codesandbox