react-navigation 타입 처리

Tags
react-native
navigation
TS
부가설명
Screen 컴포넌트 프롭 type 처리
 

Props, Navigation 프롭

import { StackScreenProps } from '@react-navigation/stack'; type RootStackParamList = { Home: undefined; Profile: { userId: string }; Feed: { sort: 'latest' | 'top' } | undefined; }; type Props = StackScreenProps<RootStackParamList, 'Profile'>; function ProfileScreen({ route, navigation }: Props) { // ... }
공홈에서는 컴포넌트 파일에서 Props 타입을 반복해서 만들기 보다는 types.tsx라는 파일을 따로 만들어서 원하는 곳에 import 하여 사용하는 방법을 추천하고 있다.