React native shouldComponentUpdate在react native中不起作用

React native shouldComponentUpdate在react native中不起作用,react-native,React Native,这是一个简单的演示。 //数据演示 { 筛选器选项:{id:'xxx',名称:'yyy'}, 列表:[{id:'xxx',name:'yyy',msg:'zzz'},] } //组件演示 类根扩展了React.Component{ shouldComponentUpdate(新道具){ console.log(newProps)//工作 } render(){ 让{filterOption,list}=this.props; 返回 } } 类过滤器扩展了React.Component{ shou

这是一个简单的演示。

//数据演示
{
筛选器选项:{id:'xxx',名称:'yyy'},
列表:[{id:'xxx',name:'yyy',msg:'zzz'},]
}
//组件演示
类根扩展了React.Component{
shouldComponentUpdate(新道具){
console.log(newProps)//工作
}
render(){
让{filterOption,list}=this.props;
返回
}
}
类过滤器扩展了React.Component{
shouldComponentUpdate(新道具){
console.log(newProps)//不工作
}
render(){//是本机组件。
返回
}
}
问题:


筛选器中的shouldComponentUpdate方法不起作用。有人能帮我吗?当props.list发生更改时,我希望防止仅在props/state发生更改时调用过滤器重新加载程序shouldComponentUpdate。由于您的代码不会在
过滤器
组件中或其上更改状态/道具,因此无需调用
shouldComponentUpdate
(初始装载渲染时不调用它)。

shouldComponentUpdate
仅在道具/状态更改时调用。由于您的代码不会在
过滤器
组件中或其上方更改状态/道具,因此无需调用
shouldComponentUpdate
(初始装载渲染时不调用该函数)。

您必须根据是否需要刷新的条件返回布尔值

shouldComponentUpdate(下一步,下一步状态){
return nextState.count!=this.state.count;
}

无论是否需要刷新,都必须根据条件返回布尔值

shouldComponentUpdate(下一步,下一步状态){
return nextState.count!=this.state.count;
}

应更新组件
触发道具/状态更改

参考文件:

实现示例:

shouldComponentUpdate(nextrops:Object,nextState:Object){
返回(
!\uu.isEqual(下一步,这个.props)| |!\uu.isEqual(下一步,这个.state)
);
}

应更新组件
触发道具/状态更改

参考文件:

实现示例:

shouldComponentUpdate(nextrops:Object,nextState:Object){
返回(
!| isEqual(nextProps,this.props)| |!!.isEqual(nextState,this.state)
);
}

您可以将应用程序状态与组件WillReceiveProps一起使用来控制组件可见性。选中此项->您可以将应用程序状态与组件WillReceiveProps一起使用来控制组件可见性。选中此项->