React calculator - async state?

I’m working on the front end calculator challenge using react. Things were going swimmingly until I wanted to clear the display if the user enters a number after hitting equals. The logic seems sound, but the display doesn’t clear and the new number is added to the operand:

I think the problem is on lines 133-137. As far as I can tell React doesn’t update state fast enough to use in this calculation. Is that the correct interpretation?

  • Should I use another method to store the key variables, and maybe just update display with state?
  • Is there a way to make React update state faster?

Keen to understand rather than just botch my way through.

Thanks in advance!

Oops! Sorry, let me edit the post above so this makes sense…

The issue is if the user hits another number after hitting equals.

In other words, if we’ve hit equals and a result is showing, when you hit a new number it should clear the screen and start from that number.

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