In the lesson React: Optimize Re-Renders with shouldComponentUpdate, setState
is used in a way that was discouraged in a previous lesson. In this lesson, it’s used as:
addValue() {
this.setState({
value: this.state.value + 1
});
}
Shouldn’t this be used with a callback to ensure that the state is correct when it’s eventually executed?
addValue() {
this.setState(state => ({
value: state.value + 1
}));
}