DEV Community

peter-lelkes
peter-lelkes

Posted on

Update the state in vanila React (without Hooks)

I got this array of objects. I want to update the state with a button click

My array of object
...
constructor(props) {
super(props)
this.state = {
players: [
{ number: null, points: null }
]
}
}
...
my update function:
...
onAddOneClick = () => {
this.setState = ((state) => ({
...state, number: this.state.players.number,
...state, points: this.state.players.points + 1}
)
)
}
...
number i get from a input
...
onNumberEntered = (event) => {
event.preventDefault();
this.setState({number: event.target.value});
}
...
I have unsuccessfully tried console.log to see if my updates code works. Can you help me and check if I did the right thing?

Thanks in advance
Regards
Peter

Top comments (0)