navigate 시 추가 프롭 전달하기

Column
Tags
navigate
params

스택 네비게이션 예시

import * as React from 'react'; import { Button, View, Text } from 'react-native'; import { NavigationContainer } from '@react-navigation/native'; import { createStackNavigator } from '@react-navigation/stack'; function HomeScreen({ navigation: { navigate } }) { return ( <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> <Text>This is the home screen of the app</Text> <Button onPress={() => navigate('Profile', { names: ['Brent', 'Satya', 'Michaś'] }) } title="Go to Brent's profile" /> </View> ); } function ProfileScreen({ navigation, route }) { return ( <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> <Text>Profile Screen</Text> <Text>Friends: </Text> <Text>{route.params.names[0]}</Text> <Text>{route.params.names[1]}</Text> <Text>{route.params.names[2]}</Text> <Button title="Go back" onPress={() => navigation.goBack()} /> </View> ); } const Stack = createStackNavigator(); function App() { return ( <NavigationContainer> <Stack.Navigator initialRouteName="Home"> <Stack.Screen name="Home" component={HomeScreen} /> <Stack.Screen name="Profile" component={ProfileScreen} /> </Stack.Navigator> </NavigationContainer> ); } export default App;