Passing params to tab navigator React Navigation 5

前端 未结 1 1655
自闭症患者
自闭症患者 2021-01-18 00:28

I’m using materialTopTabs and it seems like this loads all the screens in the navigator once its mounted. I have a screen List and inside it a

1条回答
  •  感动是毒
    2021-01-18 01:06

    Pass params to the navigator and then expose it to the tabs using React Context.

    Create a context in a separate file which you can import in both your navigator and screens:

    export const NetworkContext = React.createContext();
    

    Then provide the params in the context:

    const PostsTabNav = createMaterialTopTabNavigator();
    
    const PostsMainNav = ({ route }) => {
      return (
        
          
            
            
          
        
      );
    };
    

    In your screen component, use the context:

    const network = React.useContext(NetworkContext);
    

    Also see https://reactnavigation.org/docs/hello-react-navigation#passing-additional-props

    0 讨论(0)
提交回复
热议问题