javascript - Navigation.navigate is not a function, navigation is undefined
问题描述
I have a problem, in React-Native.
<Button title="Save" onPress = {() => navigation.navigate('Save' , { image })}/>
{image && <Image source = {{uri: image}} style= {{flex: 1}}/>}
</View>
);
}
I got an error:
navigation.navigate is not a function. (In 'navigation.navigate('Save', {image: image})', 'navigation.navigate' is undefined)
解决方案
Give your component a navigation
prop like shown below.
Also make sure that it's added in Navigation stack.
function YourComponentName({navigation}){
return (
<View>
<Button title="Save" onPress = {() => navigation.navigate('Save' , { image })}/>
{image && <Image source = {{uri: image}} style= {{flex: 1}}/>}
</View>
);
}
You can also use useNavigation
hooks
推荐阅读
- javascript - 在 d3.js v6 中以编程方式打开嵌套、折叠(隐藏)节点
- django - 在模型对象保存时刷新 UUID
- three.js - ThreeJS 着色器无法在 Chrome 上的 OnePlus 手机上正确渲染
- reactjs - moment JS 和 moment-timezone JS 解析和显示给定时区的问题
- r - 将线性回归模型应用于成对列
- rabbitmq - 在 RabbitMQ 上安装 Openstack 失败 - Centos8
- python - 在 python 中使用多处理生成唯一的值集
- mysql - 编写与 MySQL 查询等效的 MSSQL (2019) 查询
- python - 随机数作为文件名
- swiftui - 具有多个编辑按钮的 SwiftUI 表单