Passing props with screen option in DrawerNavigator

后端 未结 2 1388
天涯浪人
天涯浪人 2020-12-18 05:41

I am using DrawerNavigator in https://reactnavigation.org/docs/navigators/drawer.

const MyApp = DrawerNavigator({
    Home: {
        screen: MyHomeScreen,
          


        
相关标签:
2条回答
  • 2020-12-18 06:33

    Better way in many cases I think:

    screen: (props) => <MyNotificationsScreen {...props} propName={val1} />
    

    This will put your nav props in props.navigation.state.params. If you want them to appear in this.props instead (which will mean your component is not tightly coupled to react-navigation) then use:

    screen: (props) => <MyNotificationsScreen {...props.navigation.state.params} propName={val1} />
    
    0 讨论(0)
  • 2020-12-18 06:33

    You do have two options here:

    1- You pass the parameter in the 'navigate call':

    this.props.navigation.navigate('Notifications1', {propName: 'val1'})
    

    2- The other way around is to create Notifications1

    class Notifications1 
    {
      render ( )
      {
        return <MyNotificationsScreen propName="val1" />
      }
    }
    
    0 讨论(0)
提交回复
热议问题