Sometimes it’s desired to decide within an updater function if an update to re-render should be triggered. Calling .setState null .setState
with
no longer triggers an update in React 16. This means we can decided if the state gets updated within our
method itself!
selectCity = evt => {
const newValue = evt.target.value;
this.setState(state => {
if (state.city === newValue) {
return null;
}
return {
city: newValue
};
});
};