我是本地反应新手,我正在尝试为我的项目实现反应原生滑动器
render() {
return (
<Swiper
loop={false}
showsPagination={false}
index={1}>
<View style={this.viewStyle()}>
<ActivityScreen />
</View>
<Swiper
horizontal={true}
loop={false}
showsPagination={false}
index={1}>
<View style={this.viewStyle()}>
<YourGroups />
</View>
</Swiper>
<View style={this.viewStyle()}>
<AlertScreen />
</View>
</Swiper>
)
}
}
但是当我在组件屏幕并单击按钮时
<Button title="thank you" onPress={()=>this.props.navigation.navigate("ThankScreen")} ></Button>
我收到错误
undefined不是一个对象(评估'this.props.navigation.navigate'(
我遇到了同样的问题并使用 React Navigation 5 修复了它,它允许您使用useNavigation
钩子从任何组件访问导航道具:
import React from 'react';
import { Button } from 'react-native';
import { useNavigation } from '@react-navigation/native';
const GoToButton = ({ screenName }) => {
const navigation = useNavigation();
return (
<Button
title={`Go to ${screenName}`}
onPress={() => navigation.navigate(screenName)}
/>
);
}