Can someone please help me with my ReactJS counter Component

Hello I am writing some simple components to learn ReactJS and I have coded myself into a corner I think with this one,

I want to write a component that has a counter (just an integer displayed on the screen, and 4 buttons that, when pressed will add their number to the counter, so pressing number 10 adds 10 to the counter/running total display

I have got this far but I am confused can anyone see what I am doing wrong in the below link:

[https://github.com/JoshuaAdrianJones/freecodecamp/blob/master/1.projects/react_run/src/counter.js]

I was trying to follow this:

[https://codepen.io/flaviocopes/pen/QzEQPR?editors=0010]

One potential issue is that you are trying to pass this.updateCounter to the Button component from the Counter component, but it is not a defined method in the Counter component.

Another thing to look at is I dont see any methods on the counter that change the count state. To change state inside a method you can use the function this.setState.

1 Like