React State Is Not Assigning Properly With Setstate
I'm creating a very basic todo app. But I'm getting an issue with pushing todos into an array and assigning them to the state. constructor(props){ super(props); this.stat
Solution 1:
setStateis an async operation but it does allow a callback to be triggered when the operation is complete. Change your code to
this.setState({ todo }, () =>console.log(this.state.todo));
and you'll see the latest changes you made to the state.
Post a Comment for "React State Is Not Assigning Properly With Setstate"