[RESOLVED][Pomodoro clock] Reset action is not updating state on the page

[RESOLVED][Pomodoro clock] Reset action is not updating state on the page
0

#1

Hi, everyone!

I almost finished Pomodoro Clock project, but I have a problem with resetting state in React (it should be the simplest thing to do). When I press reset button, time in Timer (where count down is going own) is resetting, but Break Time and Session Time shows minutes the user input. However, devtools show me the state is updated, but somehow the change is not transferred to the screen. Any ideas on where the bug might be?

Anna


#2

Hello! Project looks good so far! I’m not sure, but it could be an issue with binding “this” in your classes as it doesn’t look like you are doing that. This medium article might help: https://medium.freecodecamp.org/react-binding-patterns-5-approaches-for-handling-this-92c651b5af56. Otherwise (but not as likely since it looks like you’re using setState properly) it could be an issue with mutating state. In that case, the spread operator or Object.assign() would help.


#3

I am using public class fields (fancy name for arrow functions in React), so there’s no need to bind.

The problem was with state mutation - I was changing the state at two different places/components, thus on reset parent component was updated while the child wasn’t. It took me so much time to figure out the bug!