jkomyno / react-native-user-inactivity

Simple component that alerts when the user is inactive (i.e. when the App surface hasn't been touched for X ms)
MIT License
198 stars 53 forks source link

Support changing `onAction` prop #59

Open filiptdz opened 1 year ago

filiptdz commented 1 year ago

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.

abdemirza commented 1 year ago

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 commented 2 months ago

use this https://github.com/MuhammadRafeh/react-native-inactivity