Need help with react state

i was making react javascript calculator but i encountered a problem which i do not understand i tried a lot of things but nothing worked

the above link contains code and debug logs
the project to this point work great when manually testing but when i use fcc bundle it misbehave and revert the state to previous state even though the updated state is clearly being printed and is showing that is changed

1 Like

hello,
Could you please share the link to your project with the fcc test bundle so we can see this misbehavior? thanks in advance

Did you read the note about React 18?

When I use the old render method, the only three tests that fail are ones that are in fact failing.

  • Multiple inputs of 0 should result in one 0

  • Multiple inputs of . should result in one .

  • 5 * - + 5 should output 10 not -25


When asking for help, make it easy for people to help you.

the error was caused because i was using

setExpression(expression+clickedbutton);

instead of

setExpression(prev=>prev+clickedbutton);

this approach helps to always have the latest state even with react pilling multiple state change on top of each other.

i have posted the solution to the problem in some other comment in this post so check that out.

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