从其他组件访问数据-React Native [英] Access data from other component -React Native
本文介绍了从其他组件访问数据-React Native的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须访问先前组件中的对象才能在当前组件中显示.我正在尝试发送状态参数作为Navigation方法的第二个参数.
I have to access object from previous component to show in current component. I'm trying to send a state params as second parameter of navigate method.
this.props.navigation.navigate('detail', { objPass: this.state.stObjPass });
尝试访问显示为未定义"的当前组件中的值
while trying to access the value from current component displaying as 'Undefined'
async componentWillMount() {
console.log(this.props.state.params.objPass);
console.log(this.props.objPass);
console.log(this.props.state.objPass);
}
它们全部返回空值或未定义.
All of them returning either empty or undefined.
请让我知道如何共享对象.
Please let me know how to share object.
推荐答案
它是this.props.navigation.state.params.objPass
,因此您的引用不正确.
It's this.props.navigation.state.params.objPass
, so you're just having an incorrect reference.
这篇关于从其他组件访问数据-React Native的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文