如何防止道具中的映射Redux调度导致React中的重新渲染

时间:2019-07-30 22:43:41

标签: reactjs redux react-redux

我想知道如何减少由于映射到道具的动作的参照不一致导致的重新渲染。

1 个答案:

答案 0 :(得分:0)

您可以利用shouldComponentUpdate生命周期钩子并查看nextProps,或者在this.props和nextProps之间进行比较,并根据要在特定实例中重新渲染而返回true或false。


class YourComponent extends Component {

   //....

   shouldComponentUpdate(nextProps) {
     // Compare property of this.props to nextProps 
     // or look directly to nextProps and return true or false
   }


   //...

}
相关问题