Suppose I have a state,
state = {
counter: 0
}
On the click of button I want to update the state.
My updateCounter function is this,
updateCounter = () => {
this.setState({counter: 1})
}
Which work perfectly.
I come across situation where people are using this,
updateCounter = () => {
this.setState(prevState => ({
...prevState,
counter: prevState.counter + 1
}))
}
My question's are,
What is the difference between them?
Why we have 2 setState?
Is there any performance gain of using any one?