react-native - 反应本机 this.props.navigation 在主应用程序中未定义
问题描述
我试图在我的主要反应原生应用程序中使用“this.props.navigation”,但它是未定义的。在 TabNavigator 和 ScreenNavigator 附带的我的其他组件中,它可以工作。
我的 App.js
const MyTabView = TabNavigator(
{
Projects: { screen: Projects },
Explorer: { screen: Explorer },
Profil: { screen: Profil }, ...
}
);
const StackView = StackNavigator(
{
global: {
screen: MyTabView,
headerMode: "none",
header: null,
navigationOptions: {
header: null
}
},
TermsOfUse: { screen: TermsOfUse },
LegalNotice: { screen: LegalNotice },
Options: { screen: Options }, ...
}
);
export default class App extends React.PureComponent {
constructor (props) {
super(props);
console.log(this.props.navigation); // <---------- UNDEFINED
}
render() {
return (
<Provider store={store}>
<PersistGate
loading={<ActivityIndicator />}
persistor={persistor}>
<View style={styles.fullScreen}>
<StackView />
<Tutorial navigation={this.props.navigation} /> // <---------- this.props.navigation is UNDEFINED
</View>
</PersistGate>
</Provider>
);
}
}
解决方案
navigation
prop 仅适用于导航堆栈中的组件或使用withNavigation
HOC的子组件。
推荐阅读
- python - 检查给定数是否为素数,如果是素数,则查找该数的阶乘,如果不是素数,则打印该数的数字总和
- security - Appian 的低代码系统建议的基于文件夹层次结构的安全性是否在其他地方使用?
- or-tools - 如何在 ORTools 中创建协作 VRP?
- python - Tkinter grid_size() 函数行为不当
- flutter - Flutter MIUI 通知设置
- python - 有没有办法增加matplotlib中所有子图的轴的厚度,Python
- typescript - 如何使用“忘记”属性类型(“任何”而不是“字符串”|“布尔”等)获取类/接口类型克隆?
- python - 遍历 YAML 对象
- go - Golang SFTP 目录观察器执行 Lstat 失败
- magento2 - 从 Magento 2.3.3 升级到 Magento 2.4.2 会导致引用损坏错误