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

Support changing onAction prop #59

Open
filiptdz opened this issue Apr 5, 2023 · 2 comments
Open

Support changing onAction prop #59

filiptdz opened this issue Apr 5, 2023 · 2 comments

Comments

@filiptdz
Copy link

filiptdz commented Apr 5, 2023

The timers ignore changes to onAction, therefore when it changes the timeout calls the first version of the function that was passed, and not the latest. This is what causes issues like #46 and #54. I imagine the solution might not be that straightforward, since resetting the timer every time this prop changes would be unwanted, but perhaps a good solution would be to use a ref to the onAction inside the timeout callback, and updating that ref with the value of onAction on every render. This way, a stale closure isn't called when the timeout ends.

@filiptdz filiptdz changed the title Support changing onAction prop Support changing onAction prop Apr 5, 2023
@abdemirza
Copy link

I was facing the same issue as the function was calling the old version and fixed it by creating the copy of the state and storing it into useRef

@MuhammadRafeh
Copy link

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

3 participants