thibaultboursier / use-timer

A timer hook for React
MIT License
198 stars 24 forks source link

Updating initial time won't update the timer #77

Open eddsaura opened 2 years ago

eddsaura commented 2 years ago

Hey wassup,

I am changing the initial time when a state is changing ( so it should be re rendernig ) but is not updating to the new time.

The logic behind is, we have an event with start date and end date. So, when the event is not started it shows the timer to the start of the event, and when the event is running it should show the time left until the end of said event.

Also, if you are in another tab the countdown seems to stop, it could be easily fixable checking the time again, but since changing the initial time won't update it's difficult.

thibaultboursier commented 2 years ago

Hey @eddsaura,

Thanks for opening this issue.

Could you create a reproductible example of this issue, for example on https://stackblitz.com/?

Thanks.

sasweb commented 2 years ago

Hi @thibaultboursier, I have a similar issue as @eddsaura I guess. Here's a demo: https://stackblitz.com/edit/react-dpshem?file=src/App.js

Issue 1: click "Update initial to 20", see nothing happens. Expected from my side: initialTime is set to 20. Issue 2: click "Add 20" and afterwards "Start". See 20 is added to the initial time but removed as soon as timer is started. This is for me even more critical and feels related.

What do you think?

Thanks!

thibaultboursier commented 2 years ago

Hello @pawelsas,

Thanks for your comment and your demo. I'm going to check that.

eddsaura commented 2 years ago

Sorry! I finally had to do it myself. Thanks for answering tho! <3

chaoli23 commented 2 years ago

same issue, any workaround?

andy-todd-dev commented 2 years ago

same issue, any workaround?

This issue has been fixed on the 'develop' branch (although a reset is required before a new initialTime is reflected). Unfortunately there is no release, but I've used it without issue.

danielrobertson commented 2 years ago

+1. Thank you for raising, @eddsaura! Came here to discuss the same issue.

My use case is building a Pomodoro timer in React where I want to reset the timer back to various initialTime using a useState variable within the component, but noticing initialTime does not change after its initial set value.