Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically change header title on react navigation 5.x

I have recently updated my project to react navigation 5.x. In earlier version we used to set header title as follows :

static navigationOptions = ({ navigation }) => ({
        title: 'find',
});

This is not working on React Navigation 5.x. Please Suggest.

like image 531
Rizwan Avatar asked May 29 '20 07:05

Rizwan


1 Answers

You can do it via 2 methods;

1: Set options to be a variable from your screen and keep your current code:

<Stack.Screen
  name="Label"
  component={Component}
  options={Component.navigationOptions}
/>

// component
static navigationOptions = {
  title: 'find',
};

2: By using setOptions in your component:

<Stack.Screen
  name="News"
  component={News}
  options={{
    title: 'Default',
  }}
/>

// component
this.props.navigation.setOptions({title: 'find'});
like image 76
Abdul Sadik Yalcin Avatar answered Sep 22 '22 17:09

Abdul Sadik Yalcin