reactjs - 通过反应导航将参数传递给路由但结果未定义
问题描述
嗨,我是新来的本地人,并试图学习一些东西。我正在尝试从 rest API Laravel 传递数据。这是我的代码
if (responseData.items) {
this.props.navigation.push('SearchResults', {users: responseData.items });
} else {
this.setState({ errorMessage: 'No results found'});
}
我的代码导航器
const Sp2hpStack = createStackNavigator({
搜索:SearchScreen,SearchResults:SearchResults,});
我的代码结果
render() {
const { users } = this.props.navigation.state;
console.log(users);
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>email : {users.email} </Text>
</View>
);
}
但结果未定义请帮助我
解决方案
要从路由中获取参数,您可以通过this.props.navigation.getParam('users', [])访问它们
PS:空数组是可选的,如果用户未定义,这将是默认值
推荐阅读
- oracle - 如果缺少第二高值,则使用员工表中的最高工资值
- c++ - 如何修复 boost::asio 的阻塞调用?
- c++ - 在配置 OpenCV 和 Visual Studio 时无法打开文件 python37_d.lib
- node.js - 为什么我的图像无法显示且未定义?
- php - 如何从 session.use_cookies 中删除特定会话?
- forms - 普通部分之间的谷歌表单计时器部分
- socket.io - Svelte/Sveltekit 和 socket.io-client 在开发中不工作(在预览中工作)
- bash - 循环遍历 csv 中的两列以在 bash 中使用 bulk-bing-image-downloader 抓取图像
- c++ - 为什么这个程序不产生任何输出(std::cout,斐波那契数列)?
- python - 有没有办法改变图形的颜色,使其在色谱中是连续的?