React native 更改状态后重新启动当前屏幕
我使用react native router flux,为了更改某些屏幕的某些状态,我执行以下操作: index.jsReact native 更改状态后重新启动当前屏幕,react-native,react-native-router-flux,React Native,React Native Router Flux,我使用react native router flux,为了更改某些屏幕的某些状态,我执行以下操作: index.js showMenuIcon(value) { this.setState({ viewMenu: value }); } ... <Scene renderMenuButton={this.showMenuIcon} key="menu" component={
showMenuIcon(value) {
this.setState({
viewMenu: value
});
}
...
<Scene
renderMenuButton={this.showMenuIcon}
key="menu"
component={Services}
hideNavBar={true}
/>
<Scene
renderMenuButton={this.showMenuIcon}
key="profile"
component={Profile}
hideNavBar={true}
/>
showMenuIcon(值){
这是我的国家({
视图菜单:值
});
}
...
Menu.js
<Button
title="Test button"
buttonStyle={[styles.button, styles.blue_button]}
onPress={() => this.props.renderMenuButton(true)}
textStyle={{ fontSize: 14 }}
/>
this.props.rendermenubton(true)}
textStyle={{fontSize:14}
/>
不仅状态发生变化,而且还会再次渲染当前屏幕。
如何修复
PS:对不起,我的英语…默认情况下,shoulldcomponentupdate返回true。这就是我们在上面看到的“随时更新一切”的原因。但是,如果需要性能提升,您可以覆盖shouldComponentUpdate以提供更多的“智能”。您可以在不想触发重新渲染时告诉React,而不是一直让React重新渲染 当React来渲染组件时,它将运行shouldComponentUpdate,并查看它是否返回true(组件应该更新,也称为重新渲染)或false(React这次可以跳过重新渲染)。因此,您需要覆盖shouldComponentUpdate,根据需要返回true或false,以告知React何时重新渲染以及何时跳过 示例:
shouldComponentUpdate(nextProps) {
const differentTitle = this.props.title !== nextProps.title;
const differentDone = this.props.done !== nextProps.done
return differentTitle || differentDone;
}
你能和我们分享一下你在世博会上的项目吗?