setstate in react with prevstate code example
Example 1: this.setstate prevstate
this.setState(prevState => ({ n: !prevState.n }))
Example 2: prevstate in react
handleClick() {
this.setState(prevState => {
return {
count: prevState.count + 1
}
})
}