嗨,我有以下功能组件,它本身就能完美地工作。
function MeditationList({route, navigation}) {
const adress = route.params;
return (
<View>
<HeaderBar />
<Text>
You have a number of {JSON.stringify(adress.item.numMed)} meditations
</Text>
</View>
);
}
但当我试图将它包含在一个类组件中时,它却不能工作,给我以下错误信息。
class PreScreen extends Component {
meditationList = ({route}) => {
const adress = route.params;
return (
<Text>
You have a number of {JSON.stringify(adress.item.numMed)} meditations
</Text>
);
};
render() {
return (
<ScrollView>
{this.meditationList()}
</ScrollView>
);
}
我想是我犯的一些愚蠢的错误。谢谢你。
如果你想使用路由,你应该使用this.props.route。
class PreScreen extends Component {
meditationList = () => {
const adress = this.props.route.params;
return (
<Text>
You have a number of {JSON.stringify(adress.item.numMed)} meditations
</Text>
);
};
render() {
return (
<ScrollView>
{this.meditationList()}
</ScrollView>
);
}