# \[Javascript Calculator\] setState not run as expected

**URL:** <https://forum.freecodecamp.org/t/javascript-calculator-setstate-not-run-as-expected/220424>\
**Category:** General\
**Created:** [August 23, 2018, 8:50am UTC](https://forum.freecodecamp.org/t/javascript-calculator-setstate-not-run-as-expected/220424 "2018-08-23T08:50:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![KhoaNam225](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/khoanam225/32/93910_2.png) [@KhoaNam225](https://forum.freecodecamp.org/u/KhoaNam225)\
**Post date:** [August 23, 2018, 8:50am UTC](https://forum.freecodecamp.org/t/javascript-calculator-setstate-not-run-as-expected/220424/1 "2018-08-23T08:50:47Z")

</div>

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:

[https://codepen.io/KhoaNam225/pen/dqoggg](https://codepen.io/KhoaNam225/pen/dqoggg)

---

<div class="post-metadata">

**Author:** ![DanielSubat](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/danielsubat/32/80962_2.png) [@DanielSubat](https://forum.freecodecamp.org/u/DanielSubat)\
**Post date:** [August 23, 2018, 9:30am UTC](https://forum.freecodecamp.org/t/javascript-calculator-setstate-not-run-as-expected/220424/2 "2018-08-23T09:30:49Z")

</div>

There is an inconsistency with your variable names:

```auto
  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 
/>

```

---

<div class="post-metadata">

**Author:** ![KhoaNam225](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/khoanam225/32/93910_2.png) [@KhoaNam225](https://forum.freecodecamp.org/u/KhoaNam225)\
**Post date:** [August 23, 2018, 9:37am UTC](https://forum.freecodecamp.org/t/javascript-calculator-setstate-not-run-as-expected/220424/3 "2018-08-23T09:37:58Z")

</div>

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. 😃 Very appreciate your support

---

<div class="post-metadata">

**Author:** ![DanielSubat](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/danielsubat/32/80962_2.png) [@DanielSubat](https://forum.freecodecamp.org/u/DanielSubat)\
**Post date:** [August 23, 2018, 9:42am UTC](https://forum.freecodecamp.org/t/javascript-calculator-setstate-not-run-as-expected/220424/4 "2018-08-23T09:42:53Z")

</div>

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

Glad to help & happy coding!

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:17pm UTC](https://forum.freecodecamp.org/t/javascript-calculator-setstate-not-run-as-expected/220424/5 "2021-01-17T20:17:06Z")

</div>

Closed on January 17, 2021, 8:17pm UTC


