# Components Section 8 - Updating the State

**URL:** https://forum.codewithmosh.com/t/components-section-8-updating-the-state/15741
**Category:** React
**Created:** [October 8, 2022, 7:07pm UTC](https://forum.codewithmosh.com/t/components-section-8-updating-the-state/15741 "2022-10-08T19:07:16Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jp2code](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jp2code/32/4681_2.png) [@jp2code](https://forum.codewithmosh.com/u/jp2code)
#### Post date: [October 8, 2022, 7:07pm UTC](https://forum.codewithmosh.com/t/components-section-8-updating-the-state/15741/1 "2022-10-08T19:07:16Z")

</div>

I’m following your React course that I purchased, but there is a problem.

1. In the Components section,
2. In #8 Updating the State,
3. You said to put ‘counter’ in the value

 ![8-Updating The State Video](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/9/9a80d9e2fa1ac4d9327d0f997c476e22437d3b60.png)

I did that in my code, but I get an error that ‘value’ is undefined.

How do I debug this?

The next section builds on this part, so I cannot move forward.

---

<div class="post-metadata">

### Author: ![jp2code](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jp2code/32/4681_2.png) [@jp2code](https://forum.codewithmosh.com/u/jp2code)
#### Post date: [October 8, 2022, 7:07pm UTC](https://forum.codewithmosh.com/t/components-section-8-updating-the-state/15741/2 "2022-10-08T19:07:53Z")

</div>

Here is my code:

 ![8-Updating The State My Code](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/6/6b9c024c6e2c9cc869f411489101f4bcc87ae78f.png)

---

<div class="post-metadata">

### Author: ![jp2code](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jp2code/32/4681_2.png) [@jp2code](https://forum.codewithmosh.com/u/jp2code)
#### Post date: [October 8, 2022, 7:08pm UTC](https://forum.codewithmosh.com/t/components-section-8-updating-the-state/15741/3 "2022-10-08T19:08:33Z")

</div>

Here is the error, as shown in my Chrome browser:

 ![8-Updating The State Chrome](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/5/5c75cfa270ef61ca8f85f1527c68e0feea07fefc.png)

---

<div class="post-metadata">

### Author: ![onlyhasbi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/onlyhasbi/32/4608_2.png) [@onlyhasbi](https://forum.codewithmosh.com/u/onlyhasbi)
#### Post date: [October 9, 2022, 11:03am UTC](https://forum.codewithmosh.com/t/components-section-8-updating-the-state/15741/4 "2022-10-09T11:03:17Z")

</div>

the value should be initialized to 0 (zero)

check it [here](https://codesandbox.io/s/button-example-31teeu)

---

<div class="post-metadata">

### Author: ![jp2code](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jp2code/32/4681_2.png) [@jp2code](https://forum.codewithmosh.com/u/jp2code)
#### Post date: [October 10, 2022, 12:33pm UTC](https://forum.codewithmosh.com/t/components-section-8-updating-the-state/15741/5 "2022-10-10T12:33:02Z")

</div>

Setting the value to 0 (zero) does work, but the tutorial video was showing how to pass the counter in the props.

My first post here showed 3 circles to show 1. What Section, 2. What Chapter, and 3. The Code from the video. Those are all from a screenshot of the video at time 4.29.

Is the video incorrect?

---

<div class="post-metadata">

### Author: ![UniqueNospaceShort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/uniquenospaceshort/32/1814_2.png) [@UniqueNospaceShort](https://forum.codewithmosh.com/u/UniqueNospaceShort)
#### Post date: [October 10, 2022, 3:10pm UTC](https://forum.codewithmosh.com/t/components-section-8-updating-the-state/15741/6 "2022-10-10T15:10:15Z")

</div>

Hi,

You can compare with a version I did.

[Code @GitHub](https://github.com/UchiTesting/MH-React/tree/master/counter-app/src/components)

I do not remember the code being wrong in that part.  
However I might have used different names than in the course but it should be self explanatory.

Good luck.

---

<div class="post-metadata">

### Author: ![onlyhasbi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/onlyhasbi/32/4608_2.png) [@onlyhasbi](https://forum.codewithmosh.com/u/onlyhasbi)
#### Post date: [October 11, 2022, 3:08am UTC](https://forum.codewithmosh.com/t/components-section-8-updating-the-state/15741/7 "2022-10-11T03:08:45Z")

</div>

try to understand the concept single source of truth

[Counter Demo](https://codesandbox.io/s/button-example-31teeu?file=/src/component/counters.jsx)
