Maciej Dończyk
Maciej Dończyk

Reputation: 39

How to access data from navigateOptions of Navigation Drawer

I have a trouble with getting data from props in my Sidebar, I coded it like this using Navigation Drawer. How can I access for example that text ("xd") from navigationOptions or how can i pass an object there and read it correctly?

contentComponent: props => <SideBar {...props } />, navigationOptions: {
      icon: 'xd'
  },

Rest of the code

export default Sidebar = props => (
{..Something not important in that question}
          <DrawerNavigatorItems {...props} style={{
             
          }}/>
      </View>

  </ScrollView>  
);

Upvotes: 1

Views: 171

Answers (1)

bas
bas

Reputation: 15722

I'm not sure what exactly your use case is, but it might be easier to just pass icon directly to the SideBar component as a prop:

contentComponent: (props) => <SideBar {...props} icon="xd" />

Then you can retrieve the icon value passed to your SideBar component like this:

export default Sidebar = (props) => (
  <ScrollView>
    <Text>{props.icon}</Text>
  </ScrollView>
);

I've used the Text component to give an example, but replace the Text component with the views you want.

Upvotes: 1

Related Questions