Walter Shub
Walter Shub

Reputation: 662

Set the title of navigation bar based on props

How do I set the title of the navigation bar based on props, I want to do something like below.

static navigationOptions = {
title: this.props.navigation.state.params.name,

};

Upvotes: 4

Views: 6020

Answers (1)

ReyHaynes
ReyHaynes

Reputation: 3102

You can override navigationOptions in the route config to do that for you:

// Optional: Override the `navigationOptions` for the screen
navigationOptions: ({ navigation }) => ({
  title: `${navigation.state.params.name}'s Profile'`,
})

Source: https://reactnavigation.org/docs/stack-navigator.html#routeconfigs

Upvotes: 9

Related Questions