this.props.navigation.state.params 在 React Native 中未定义
this.props.navigation.state.params is undefined in React Native
我遇到过这个问题,我在其他 class 组件上使用了相同的技术,但效果很好。
输出
动作
+ [ItemCreate.js] Parent Class 组件
在这个 class 组件中我确实使用了 connect()
因为 connect()
有什么问题吗?
console.log("STATE PARAMS:", this.props.navigation.state.params.selectedCategory);
STATE PARAMS: undefined
+ [ChooseCommerce.js] Child Class 组件
this.props.navigation.navigate("itemcreate", {
selectedCategory: "phonesandcomputers"
})
试试这个方法itemcreate.js
// 2nd param is "defaultValue"
const selCategory = this.props.navigation.getParam("selectedCategory", "");
此处有更多详细信息React Navigation 4.x Route Params
我找到了解决办法。检查项目中的拼写错误。
如果一切正确,使用这个
this.props.navigation.state.params
我遇到过这个问题,我在其他 class 组件上使用了相同的技术,但效果很好。
输出
动作
+ [ItemCreate.js] Parent Class 组件
在这个 class 组件中我确实使用了 connect()
因为 connect()
有什么问题吗?
console.log("STATE PARAMS:", this.props.navigation.state.params.selectedCategory);
STATE PARAMS: undefined
+ [ChooseCommerce.js] Child Class 组件
this.props.navigation.navigate("itemcreate", {
selectedCategory: "phonesandcomputers"
})
试试这个方法itemcreate.js
// 2nd param is "defaultValue"
const selCategory = this.props.navigation.getParam("selectedCategory", "");
此处有更多详细信息React Navigation 4.x Route Params
我找到了解决办法。检查项目中的拼写错误。
如果一切正确,使用这个
this.props.navigation.state.params