Javascript React Native中未定义this.props.navigation.state.params

Javascript React Native中未定义this.props.navigation.state.params,javascript,react-native,parameters,navigation,undefined,Javascript,React Native,Parameters,Navigation,Undefined,我遇到了这个问题,我在其他类组件上使用了相同的技术,但效果很好。 输出 行动 +[ItemCreate.js]父类组件 在这个类组件中,我确实使用了connect()是否因为connect()而出现任何问题? console.log(“状态参数:”,this.props.navigation.STATE.PARAMS.selectedCategory) 状态参数:未定义 +[ChooseCommerce.js]子类组件 this.props.navigation.navigate("

我遇到了这个问题,我在其他类组件上使用了相同的技术,但效果很好。

输出


行动
+[ItemCreate.js]父类组件
在这个类组件中,我确实使用了
connect()
是否因为
connect()
而出现任何问题?
console.log(“状态参数:”,this.props.navigation.STATE.PARAMS.selectedCategory)

状态参数:未定义

+[ChooseCommerce.js]子类组件

this.props.navigation.navigate("itemcreate", {
     selectedCategory: "phonesandcomputers"
})

尝试使用这种方法创建itemcreate.js

// 2nd param is "defaultValue"
const selCategory = this.props.navigation.getParam("selectedCategory", "");

更多细节在这里

我找到了一个解决方案。检查项目中的打字错误

如果一切正常,请使用此

this.props.navigation.state.params

您使用的是哪个版本的react navigation?react navigation 4,它在其他类组件上工作,但是即使我从不同的文件复制了代码,它仍然有错误。但从另一个运行良好的类组件文件来看,我没有使用任何connect()方法。子类是导航中的一个屏幕吗?或者是在父类下的屏幕?请确保两个屏幕都选择commerce.js,ItemCreate.js必须是导航屏幕的一部分。如果没有,那么在你的情况下在他们之间传递道具是不正确的。