React:当组件在不使用componentwillupdate的情况下收到特定的道具时,您是否可以进行回调?

时间:2016-10-31 19:14:35

标签: javascript reactjs callback

我只想在更新某个道具时调用回调。我的组件非常频繁地获取更新的道具,因此检查componentwillupdate中更新了哪些道具效率非常低。

1 个答案:

答案 0 :(得分:0)

我认为您可以实现 componentWillReceiveProps 方法并检查当前道具是否与nextProps不同,并在新道具收到时更新。

componentWillReceiveProps(nextProps){
   if(this.props.propsName !== nextProps.propsName){
      // do your update logic here
   }
}