How should the new context api work with React Native navigator?

后端 未结 4 844
野性不改
野性不改 2021-01-30 18:37

I created a multiscreen app using React Navigator following this example:

import {
  createStackNavigator,
} from \'react-navigation\';

const App = createStackN         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-30 19:04

    This answer takes in consideration react-navigation package.

    You have to wrap your App component with the ContextProvider in order to have access to your context on both screens.

        import { createAppContainer } from 'react-navigation'
        import { createStackNavigator } from 'react-navigation-stack'
        import ProfileContextProvider from '../some/path/ProfileContextProvider'
    
        const RootStack = createStackNavigator({
          Home: { screen: HomeScreen },
          Profile: { screen: ProfileScreen },
        });
    
        const AppContainer = createAppContainer(RootStack)    
        const App = () => {
          return (
          
            
          );
        }
    

提交回复
热议问题