# React state changing issue

**URL:** <https://discourse.mozilla.org/t/react-state-changing-issue/84716>\
**Category:** Learn\
**Created:** [August 18, 2021, 3:55pm UTC](https://discourse.mozilla.org/t/react-state-changing-issue/84716 "2021-08-18T15:55:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayanda](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/ayanda/32/40549_2.png) [@ayanda](https://discourse.mozilla.org/u/ayanda)\
**Post date:** [August 18, 2021, 3:55pm UTC](https://discourse.mozilla.org/t/react-state-changing-issue/84716/1 "2021-08-18T15:55:20Z")

</div>

HI, I’m attempting to change the color of my h1 element using the onclickevent, but the previous color remains

 ![Screenshot (591)](https://us1.discourse-cdn.com/flex001/uploads/mozilla/original/3X/7/e/7eca0e1f825fd0fc54e16803aa414151e6ff6daa.png)

---

<div class="post-metadata">

**Author:** ![mikoMK](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mikomk/32/50456_2.png) [@mikoMK](https://discourse.mozilla.org/u/mikoMK)\
**Post date:** [August 18, 2021, 6:06pm UTC](https://discourse.mozilla.org/t/react-state-changing-issue/84716/2 "2021-08-18T18:06:02Z")

</div>

Hi @ayanda 👋

I’m not a React developer. So maybe I’m completely wrong 😬  
The `setStyle` variable in your code is just a “normal” variable. Shouldn’t it be a `state` variable like `state.text`? Maybe the `return` part can only react to variable changes if they are `state` variables.  
If this is true, you’re `clicked()` function should use `setState()` to change a `state.setStyle` variable.

Have a nice day!  
Michael

---

<div class="post-metadata">

**Author:** ![mohinder\_singh](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@mohinder\_singh](https://discourse.mozilla.org/u/mohinder_singh)\
**Post date:** [August 25, 2021, 3:01pm UTC](https://discourse.mozilla.org/t/react-state-changing-issue/84716/3 "2021-08-25T15:01:07Z")

</div>

You need to learn about react state specifically useState hook.
