[Javascript Calculator] setState not run as expected

[Javascript Calculator] setState not run as expected
0

#1

Hello, I’m building my JS calculator, I have this block of code (handleEqual() in Calculator Component )to calculate and set the result in the state of the calculator, I expected the setState() to run everytime I click the “=” button but it doesn’t, could anyone explain to me why is that? Thank you very much! This is my code:


#2

There is an inconsistency with your variable names:

  this.state = {
            currentText: "",
            previousValue: "",
            result: "0",  <-- here
            firstClick: true,
            evaluated: false
        }

[...]

<ResultScreen value={props.result}/> <-- here

[...]

<Display 
  currentText={this.state.currentText} 
 resultText={this.state.resultText}  <---and here 
/>

#3

Wow thank you so much! I didn’t thought about that, I thought it would be a problem in my logic or something like that and I tried a whole day to solve it but i couldn’t. :smiley: Very appreciate your support


#4

Sometimes when coding, you won’t see the wood for the trees :wink:

Glad to help & happy coding!