When we have to update any state which is based on the previous state then it is better to use this.state?
class Counter extends Component {
constructor(props) {
super(props)
this.state = { count: 0 }
}
changeCount() {
this.setState({
count: this.state.count + 1
})
}
}
or it is better to use function?
class Counter extends Component {
constructor(props) {
super(props)
this.state = { count: 0 }
}
changeCount() {
this.setState(prevState => ({
count: prevState.count + 1
}))
}
}