天天看點

[React] Returning null from setState in React 16

Returning 

null

 will not update state and trigger a component re-render
updateMocktail = mocktail => {
  const newMocktail = mocktail;  
  this.setState(state => {
    if (state.mocktail === newMocktail) {
      return null;
    } else {
      return { mocktail };
    }  
  })  
}