Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- mlfq
- SupportVectorMachine
- dataindependency
- softmargin
- humaninterfaceguide
- multilevelfeedbackqueue
- SVM
- dbms
- conceptualdatamodeling
- 자료구조
- 머신러닝
- 운영체제
- databasesystems
- human-interface-guide
- xv6
- softmarginsvm
- copyonwrite
- db
- threeschemaarchitecture
- MachineLearning
- database
- 기계학습
- entity-relationshipmodel
- monopolyqueue
- OperatingSystem
- ML
- Datastructure
- databasemanagementsystem
- lightweightproces
- react native #rn #리액트네이티브 #hook #hooks #훅 #navigation #네비게이션 #usenavigate
Archives
- Today
- Total
leehyogum의 트러블슈팅
[React Native] React Navigation 사용법 본문
1. 설치
npm install @react-navigation/native
npm install @react-navigation/native-stack
npm install react-native-screens react-native-safe-area-context
2. 네비게이션 컨테이너 설정
앱의 루트 컴포넌트를 NavigationContainer
로 감싸서 네비게이션을 설정한다.
import * as React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
const Stack = createNativeStackNavigator();
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Details" component={DetailsScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
3. useNavigation 훅 사용useNavigation
훅을 사용하여 네비게이션 객체에 접근해 네비게이션 동작을 수행한다.
import React from 'react';
import { Button, View, Text } from 'react-native';
import { useNavigation } from '@react-navigation/native';
function HomeScreen() {
const navigation = useNavigation();
return (
<View>
<Text>Home Screen</Text>
<Button
title="Go to Details"
onPress={() => navigation.navigate('Details')}
/>
</View>
);
}
export default HomeScreen;