Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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,

};

like image 835
Walter Shub Avatar asked Jan 28 '23 04:01

Walter Shub


1 Answers

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

like image 118
ReyHaynes Avatar answered Feb 15 '23 10:02

ReyHaynes