[React] Returning null from setState in React 16

Returning null will not update state and trigger a component re-render

 

Example:

updateMocktail = mocktail => {
  const newMocktail = mocktail;  
  this.setState(state => {
    if (state.mocktail === newMocktail) {
      return null;
    } else {
      return { mocktail };
    }  
  })  
}

 

posted @ 2020-09-01 15:10  Zhentiw  阅读(158)  评论(0编辑  收藏  举报