-
Notifications
You must be signed in to change notification settings - Fork 83
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
How to restart the timer? #42
Comments
One way I found was using history to redirect to same page. |
This is still an open issue! The inability to restart this component is a real pain. |
No need to be quite so dramatic @sjmp . What action are you proposing would reset the timer? I've not looked at this in a while, but I believe if the If I find some time over the xmas holidays I will take a look. |
@sjmp @pughpugh Setting the same time again will not work. You can do something like this Initial state from seconds received in props or fixed. You may also use default props instead ternary operator
Set state by adding fraction.
|
#45 has been fixed as well a couple of other related bugs. I'm not convinced this fully meets the requirements of resetting the timer, but might at least support a workaround for some people. |
Seems like a badly needed feature. You'll have to find a way to call the following internally:
I needed a timer that automatically reset on complete:
|
Might not be the best approach but here is what I did to force the component to re-render and therefore restart.
|
@VilliGunn Great solution, I'd even suggest adding it in the Readme as part of an FAQ section if there is no progress on implementing this feature into the base component. |
@pughpugh
and the only thing we have to do is change countDownStartedAt prop to restart it. |
Late to the party, but note for the people are still seeking for simple solution. Like https://www.npmjs.com/package/react-countdown#key mentioned, just set a new key to reset the component to restart the countdown. |
How to restart on setState or any other condition or props change, I have tried to re-render the whole component using forceUpdate() but it doesn't seem to work.
Using this clock for OTP countdown, need to reset when the user resend OTP.
The text was updated successfully, but these errors were encountered: