Javascript 使用react Native中的react navigation创建带有道具的导航按钮
我正在尝试创建一个组件按钮,它可以帮助我在堆栈之间导航。我使用react导航在应用程序中导航。问题是我有3个文件: -App.jsJavascript 使用react Native中的react navigation创建带有道具的导航按钮,javascript,react-native,react-navigation,Javascript,React Native,React Navigation,我正在尝试创建一个组件按钮,它可以帮助我在堆栈之间导航。我使用react导航在应用程序中导航。问题是我有3个文件: -App.js <SafeAreaProvider> <StatusBar barStyle="dark-content" backgroundColor="#ecf0f1" /> <NavigationContainer> <Stack.Navigator initialRouteN
<SafeAreaProvider>
<StatusBar barStyle="dark-content" backgroundColor="#ecf0f1" />
<NavigationContainer>
<Stack.Navigator initialRouteName="Accueil">
<Stack.Screen name="Accueil" component={AccueilScreen} options={{headerShown: false}}/>
<Stack.Screen name="Progression" component={ProgressionScreen} />
<Stack.Screen name="Themes" component={ThemesScreen} />
<Stack.Screen name="Quizz" component={QuizzScreen} />
</Stack.Navigator>
</NavigationContainer>
</SafeAreaProvider>
-Accueil.js
function Accueil({ navigation }) {
return (
<SafeAreaView style={styles.container}>
<View style={styles.content_container}>
<Image style={styles.logo} source={require('../assets/logo.jpg')} />
<Button buttonText="Progression" navigation={navigation}/>
</View>
</SafeAreaView>
)
}
函数accureil({navigation}){
返回(
)
}
-Button.js
export default function Button(props, navigation) {
return (
<TouchableOpacity style={styles.button} onPress={() => navigation.navigate(props.buttonText)}>
<Text style={styles.button_text}>{props.buttonText}</Text>
</TouchableOpacity>
)
}
导出默认功能按钮(道具、导航){
返回(
导航.导航(props.buttonText)}>
{props.buttonText}
)
}
我的问题是,我无法使navigation.navigate在按钮组件中工作,而当我将它直接放在acueil.js文件中时,它完全工作
你能帮我吗?
导航
是按钮组件中道具
的一部分
export default function Button({ navigation, ...props }) {
return (
<TouchableOpacity style={styles.button} onPress={() => navigation.navigate(props.buttonText)}>
<Text style={styles.button_text}>{props.buttonText}</Text>
</TouchableOpacity>
)
}
导航
是按钮
组件中的道具
的一部分
export default function Button({ navigation, ...props }) {
return (
<TouchableOpacity style={styles.button} onPress={() => navigation.navigate(props.buttonText)}>
<Text style={styles.button_text}>{props.buttonText}</Text>
</TouchableOpacity>
)
}
非常感谢,它很有效!当我试着把它放在花括号里时,我错过了道具前的3个小点。你能告诉我添加这些点的名称吗?这样我就可以了解更多有关它的信息了?Spread Operator谢谢你,它很有效!当我试着把它放在花括号里时,我错过了道具前的3个小点。请告诉我添加这些点的名称,以便我能了解更多信息,好吗