react-native - 未定义不是对象(评估 this.props.route.params.text)
问题描述
我按照 React Navigation Doc 将参数传递到我的上一个屏幕,但是当我在上一个屏幕中访问它时出现错误说
评估 this.props.route.params.text
export default class SelectMap extends Component{
constructor() {
super()
}
render(){
const {text} = this.props.route.params
return (
<View style={{alignItems: 'center', justifyContent:'center'}}>
<TouchableOpacity onPress={() => this.props.navigation.navigate('MapView')}>
<Text>
Open Maps
</Text>
<Text>
{text}
</Text>
</TouchableOpacity>
</View>
)
}
}
这就是我发送参数的方式
this.props.navigation.navigate('SelectMap', {text:JSON.stringify(this.state.marker)})
解决方案
您的构造函数必须如下
constructor(props) {
super(props);
}
推荐阅读
- excel - 一个宏运行,另一个不运行
- vue.js - 如何仅在某些组件中加载本地 JavaScript 文件
- javascript - 表单始终使用 Javascript 确认提交
- c++ - malloc、free、多指针,它是如何工作的?
- identityserver4 - 是否有 git hub 项目可供参考以将现有用户 Db 带到身份服务器 4?如果有,请指点我
- django - Sorl-thumbnail 不在“/cache”文件夹中生成缩略图
- javascript - 用单引号内的转义引号解析 JSON 时出错
- javascript - 有人可以帮助解释为什么它返回不同的总和吗?
- visual-studio-code - vscode给出的建议的部分自动完成?
- java - 在没有 pojo 的情况下在 spring 中进行 mongodb 查询