use-before-unload icon indicating copy to clipboard operation
use-before-unload copied to clipboard

Hook does not respond to changes in arguments

Open huan086 opened this issue 5 years ago • 1 comments

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].

huan086 avatar Aug 13 '19 14:08 huan086

[handleBeforeunload] argument is missing in the useEffect, to fix this

pedroteixeira avatar Mar 12 '21 21:03 pedroteixeira