Skip to content

Commit f5b24e4

Browse files
Update screen-options.md by detailing navigation.setOptions()
1 parent db23292 commit f5b24e4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

versioned_docs/version-7.x/screen-options.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,3 +502,27 @@ The `navigation` object has a `setOptions` method that lets you update the optio
502502
Update options
503503
</Button>
504504
```
505+
506+
Futhermore, `navigation.setOptions()` can be used to set Custom header components for `headerLeft`, `headerTitle` and `headerRight`
507+
508+
```js name="setOptions for navigation" snack dependencies=@expo/vector-icons
509+
import React, { useEffect } from 'react';
510+
511+
const MyScreen = ({ navigation, route, ...props }) => {
512+
useEffect(() => {
513+
// Setting custom header components
514+
navigation.setOptions({
515+
headerLeft: <CustomHeaderLeftComponent {...props} />, // Custom component on the left
516+
headerTitle: <CustomHeaderTitleComponent {...props} />, // Custom title component
517+
headerRight: <CustomHeaderRightComponent {...props} />, // Custom component on the right
518+
});
519+
}, [navigation, props]); // Adding 'props' as a dependency if required
520+
521+
return (
522+
// Your screen content
523+
<View>
524+
<Text>My Screen Content</Text>
525+
</View>
526+
);
527+
};
528+
```

0 commit comments

Comments
 (0)