Configuring the header bar
We've seen how to configure the header title already, but let's go over that again before moving on to some other options.
Setting the header title
Each screen has an options property (an object or function returning an object) for configuring the navigator. For the header title, we can use the title option:
- Static
- Dynamic
const MyStack = createNativeStackNavigator({
screens: {
Home: {
screen: HomeScreen,
options: {
title: 'My home',
},
},
},
});
const Stack = createNativeStackNavigator();
function MyStack() {
return (
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{
title: 'My home',
}}
/>
</Stack.Navigator>
);
}

Using params in the title
To use params in the title, make options a function that returns a configuration object. React Navigation calls this function with { navigation, route } - so you can use route.params to access the params:
- Static
- Dynamic
const MyStack = createNativeStackNavigator({
screens: {
Home: {
screen: HomeScreen,
options: {
title: 'My home',
},
},
Profile: {
screen: ProfileScreen,
options: ({ route }) => ({
title: route.params.name,
}),
},
},
});
const Stack = createNativeStackNavigator();
function MyStack() {
return (
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{
title: 'My home',
}}
/>
<Stack.Screen
name="Profile"
component={ProfileScreen}
options={({ route }) => ({
title: route.params.name,
})}
/>
</Stack.Navigator>
);
}
The argument that is passed in to the options function is an object with the following properties:
navigation- The navigation object for the screen.route- The route object for the screen
We only needed the route object in the above example but you may in some cases want to use navigation as well.
Updating options with setOptions
We can update the header from within a screen using navigation.setOptions:
- Static
- Dynamic
<Button
onPress={() =>
navigation.setOptions({ title: 'Updated!' })
}
>
Update the title
</Button>
<Button
onPress={() =>
navigation.setOptions({ title: 'Updated!' })
}
>
Update the title
</Button>
Adjusting header styles
There are three key properties to use when customizing the style of your header:
headerStyle: A style object that will be applied to the view that wraps the header. If you setbackgroundColoron it, that will be the color of your header.headerTintColor: The back button and title both use this property as their color. In the example below, we set the tint color to white (#fff) so the back button and the header title would be white.headerTitleStyle: If we want to customize thefontFamily,fontWeightand otherTextstyle properties for the title, we can use this to do it.
- Static
- Dynamic
const MyStack = createNativeStackNavigator({
screens: {
Home: {
screen: HomeScreen,
options: {
title: 'My home',
headerStyle: {
backgroundColor: '#f4511e',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
},
},
},
});
const Stack = createNativeStackNavigator();
function MyStack() {
return (
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{
title: 'My home',
headerStyle: {
backgroundColor: '#f4511e',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
}}
/>
</Stack.Navigator>
)