use-before-unload
use-before-unload copied to clipboard
Hook does not respond to changes in arguments
Initally
const [state, setState] = useState(false);
useBeforeUnload(state);
Subsequently
setState(true);
Expected result After setState, I get the prompt when navigating away.
Actual result No prompt is shown when navigating away
Code changes that's needed
Move declaration of handleBeforeunload inside of the function passed to useEffect. Update the dependencies of useEffect to [value]
.
[handleBeforeunload] argument is missing in the useEffect
, to fix this