You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
filiptdz
changed the title
Support changing onAction prop
Support changing onAction prop
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 theonAction
inside the timeout callback, and updating that ref with the value ofonAction
on every render. This way, a stale closure isn't called when the timeout ends.The text was updated successfully, but these errors were encountered: