Can someone explain for me why do we use this.setState(this.state)?
I don't understand why do we use "this" and why do we use this.setState(this.state)?
Giovanni P.4,803 Points
While the OP has probably already figured this out, it might be good for there to be an actual answer in case others are looking for it.
The reason we call
this.setState( this.state ) is so that React actually rerenders the page with the new state. If we just set
this.state and didn't call
this.setState( this.state ), the state variable would change, but React wouldn't know it is supposed to rerender the page.
I hope that helps!
I Dilate3,982 Points