Develop/React Native

React-navigation v5 에서 v4 때 쓰던 API 사용하는 방법 (ex. withNavigation, ... )

안다희 2020. 3. 13. 01:53
728x90

How to use withNavigation in react-native version 5

 

https://reactnavigation.org/docs/compatibility/

 

React Navigation

> Note: Before following this guide, make sure that you've followed the [Getting Started](getting-started.md) guide to setup React Navigation 5 in your app.

reactnavigation.org

다행히도, v5 이전의 API를 지원하는 패키지가 따로 있다.

If you were importing actions from react-navigation, you need to change them to import from @react-navigation/compat:

 

react-navigation에서 import 하던 것을

@react-navigation/compat 을 설치해 그대로 import 하면 된다!

 

- install

yarn add @react-navigation/compat

 

- Usage

import { withNavigation } from '@react-navigation/compat';

 

 

- 추가로, 다음과 같은 API를 지원한다. (v4 때 지원하던 API )

The library exports the following APIs:

Actions:
    NavigationActions
    StackActions
    DrawerActions
    SwitchActions
HOCs:
    withNavigation
    withNavigationFocus
Navigators:
    createSwitchNavigator
    Compatibility helpers
    createCompatNavigatorFactory - Takes a navigator with the v5 API and returns a createXNavigator with the v4 API.
    createCompatNavigationProp - Takes the v5 navigation object along with a route object and returns a v4 navigation object.

출처: https://mingos-habitat.tistory.com/34 [밍고의서식지:티스토리]