Restart the countdown timer when a user goes back to the page with the countdown timer. #223
Replies: 3 comments 2 replies
-
Hey, I guess it would be better to pass the useEffect(() => {
setKey((prevKey) => prevKey + 1);
}, [])
<CountdownTimer key={key} /> Alternatively you can unmount the component when the user navigates away and mounted back when he lands back to the page with the timer. This will solve your problem as well! |
Beta Was this translation helpful? Give feedback.
-
hi, what if you aren't using the component provided by the library? I'm using the hooks and looks like theres no way to do this, kindly help @vydimitrov |
Beta Was this translation helpful? Give feedback.
-
I'm not using the component. Only consuming the hooks and there's no way to do that? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm building out quiz like functionality for an app in react native using the circle timer. Once the timer duration lapses, I automatically redirect the user to a new page (RestartScreen). RestartScreen has a Restart Game button that returns the page with the timer. Once the user selects the Restart Game button, they're directed to the page with the countdown timer
I've tried applying a new key to the countdown component using the use Effect hook but it hasn't worked.
How can I have the timer restart when the user goes back to the screen with the countdown timer? i.e. Starts the game?
This is how my code looks at the moment. When I go back to the page with the countdown, the timer is stuck at 0.
Beta Was this translation helpful? Give feedback.
All reactions