Accessing Header inside react Component file

Viewed 37

can someone help with how to access the header from the actual component in react-navigation-6? I am trying to set the title based on some data in the component: example: how can I access this A.js file

A.js
const A = (props)=>{
       return <Text>Hello World</Text>
}
export default A

thanks

1 Answers

You can use navigation.setOptions like below

const A = (props)=> {
  useEffect(() => props.navigation.setOptions({title: 'new title'}), []);
  return <Text>Hello World</Text>
}
export default A

Ref : Updating options with setOptions

Related