简体   繁体   中英

Access Props inside const in React Native - Javascript

I've created a const like this:

 const DrawerNav =  DrawerNavigator({

    Home:{
        screen:StackNav,
        navigationOptions: {
            drawerLockMode: 'locked-closed'
        }
    },
    MonthlyReport: {
        screen:MonthlyReport
    }

},{
    contentComponent: () => <DrawerContent item={props.item}/>
})

Now I access this using:

  <DrawerNav item={item}/>

But I'm unable to access the props passed inside DrawerNav . How can I access this in:

<DrawerContent item={props.item}/>

You are forgetting to get the prop parameter:

contentComponent: props => (
  <DrawerContent {...props} />
)

Then just pass using a spread opperator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM