react-compound-timer icon indicating copy to clipboard operation
react-compound-timer copied to clipboard

Not changing initialTime dynamically

Open Jromero97 opened this issue 6 years ago • 5 comments

Hi, I'm trying to increment/decrement timer minutes using a state propety

this.state = {
  ....
  minutes: 5,  
  ....
};

render() {
    return (
        <Timer initialTime={this.state.minutes * 60000}>
              <Timer.Minutes/>:<Timer.Seconds/>
        </Timer>
    )
}

But when I trigger a function to update state, It's not changing the value in Timer.

Jromero97 avatar Aug 01 '19 04:08 Jromero97

@Jromero97 same issue, do you have any solution?

armspkt avatar Sep 07 '19 06:09 armspkt

You should use "setTime"

see "Change props dynamically and use HOC" section https://volkov97.github.io/react-compound-timer/

by the way, now you can use "useTimer" hook - it should be more convenient then

volkov97 avatar Sep 07 '19 06:09 volkov97

Here you can see an example, which uses "setTime" from a hook

It sets timer time to 5000, after 3000 ms after mounting

https://codesandbox.io/s/elated-sutherland-6flom?fontsize=14

volkov97 avatar Sep 07 '19 06:09 volkov97

@volkov97 it works when startImmediately: true but when I startImmediately: false it does not work.

Is there a solution that I can startImmediately: false and use setTime together?

armspkt avatar Sep 07 '19 06:09 armspkt

@volkov97 can I use setTime even without hooks? I'm using 1.0 version. Is there a way for me to reset the initialTime to 0 when I'm changing the value of the time because I need to save its value and then continue again and when I click reset, I need to set the value of the time back to 0. But it resets to the last initialTime.

madzman23 avatar Jun 01 '20 22:06 madzman23