25+5 Timer breaks after adding setState

Im not sure whats going on but whenever I add ‘This.setState({time: remaining});’ to line 21 it breaks the entire timer. The timer quickly cycles between 24 and 25 until it lags out and breaks. However, without ‘This.setState({time: remaining})’ the timer works fine.

Hey I’m wondering what you would like line 50 {this.timerware(25)} to do? Currently this calls the timerware() method everytime the component rerenders. React rerenders automatically everytime its props or state changes, and so you can imagine what happens when you set remaining to your state. You enter an infinite loop of triggering timerware() → rerender → triggering timerware() until you crash.

ah I had it there to test it but thats probably whats causing it. I didnt think about it rerendering

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.