Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook does not respond to changes in arguments #1

Open
huan086 opened this issue Aug 13, 2019 · 1 comment
Open

Hook does not respond to changes in arguments #1

huan086 opened this issue Aug 13, 2019 · 1 comment

Comments

@huan086
Copy link

huan086 commented Aug 13, 2019

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

@pedroteixeira
Copy link

pedroteixeira commented Mar 12, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants