reactjs - React Native Props not Rendering to the next scene
问题描述
I am developing a Student application where at the home I have the names of the students, onPress to the names I want the app to go to a second screen and show the the Marks they got along with their name and home address.While doing this, onclick to the name of the students the new scene is loading but the props are not showing. {this.props.students} in the StudentScene is not showing anything.Also there is no error!
my home scene code is below:
import React, {Component} from 'react';
import {View, Text} from 'react-native';
import {Screen} from '../ui/Screen';
import {Card} from '../ui/Card';
import {Navigator, Scenes} from '../navigation';
type HomeProps = {};
class HomeScene extends Component<HomeProps> {
static title = 'InStore locations';
goToBoard = (students) => {
Navigator.push(Scenes.STUDENT_SCENE, {students});
};
render() {
const students = [
{ id: '1', name: 'Tony', address: 'home 18',
subject :{
MAth : "89",
Chemistry : "44"
}
},
{ id: '2', name: 'Paul', address: 'home 34',
subject :{
Latin : "80",
Physics : "47"
}
},
{ id: '3', name: 'Simma', address: 'home 56',
subject :{
MAth : "78",
History : "94"
}
},
];
return (
<Screen>
<View>
{students.map((student: any) => (
<View key={student}>
<Card onPress= {() => this.goToBoard(student)}>
<Text>{student.name}</Text>
</Card>
</View>
))}
</View>
</Screen>
);
}
}
export default HomeScene;
and the Student Scene code is below:
import React, {Component} from 'react';
import {View, Text} from 'react-native';
import {Screen} from '../ui/Screen';
type StudentProps = {students:any};
class StudentScene extends Component<StudentProps> {
render() {
return (
<Screen>
<View>
<Text>{this.props.students}</Text>
</View>
</Screen>
);
}
}
export default StudentScene;
解决方案
试试这个方法
<Text>{JSON.stringify(this.props.route.params.students)}</Text>
推荐阅读
- c# - 对 jpeg 文件使用 JpegBitmapDecoder.Create() 时出现意外的属性类型或值
- php - 我想访问 StdClass 对象的内部值
- python - 如何从输入框中获取值并将其插入文本框中
- sql-server - 在 SQL 中优化存储过程?面对错误
- android - 改造:如何等到请求调用完成后再执行下一行代码?
- python - 为什么打折奖励功能被颠倒了?
- php - PHP表单被提交但数据为空
- python - OpenAPI 生成的架构请求正文显示默认值而不是类型
- vb.net - 发布问题 VB.Net “目标 GatherAllFilesToPublish 不存在?”
- jakarta-ee - 如何控制一次执行一个无状态会话bean的方法?