React ~ Stuff - rohit120582sharma/Documentation GitHub Wiki
Returning null from setState in React 16
React 16 lets you decide whether state gets updated via .setState
to prevent unnecessary DOM updates. Calling .setState
with null
no longer triggers an update in React 16.
class Mocktail extends React.Component {
componentWillReceiveProps() {
console.log('updated either by new props or setState');
}
updateMocktail = newMocktail => {
this.setState(oldState => {
if (oldState.mocktail === newMocktail) {
return null;
} else {
return {
mocktail: newMocktail
};
}
});
}
}