我使用componentWillMount()
,因为我认为无法使用static
将setParams与状态以及GalleryScreen.navigationOptions = navData => {}
的class
之外的React.Component
一起使用。
我一直在尝试使用此方法,但总是收到以下错误:
TypeError:未定义不是对象(正在评估'props.navigation.state.params.imageData')]
我的结果是将state.pickedImage
的值从GalleryScreen.js传递到return语句内的EventInput.js。
GalleyScreen.js:这是React组件
componentWillMount() {
const {setParams} = this.props.navigation;
setParams({imageData: this.state.pickedImage})
}
EventInput.js:这只是EventInput道具(不是React组件)
return (
<Image source={{uri: props.navigation.state.params.imageData}} style={{width: 300, height: 300}}/>
);
是否有其他解决方案,以便我可以传递state.pickedImage
的值?并使用getParam
从其他组件获取它的值?
如果要访问导航,则应使用“ withNavigation”包装组件。