Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set header title dynamically inside of a component in react navigaton 6?

CategoryMealScreen.navigationOptions = navigationData => {
  const catId = navigationData.navigation.getParam('categoryId');

  const selectedCategory = CATEGORIES.find(cat => cat.id === catId);

  return {
    headerTitle: selectedCategory.title
  };
};

The above works fine with react navigation 4 inside of a component. But it doesn’t work for react navigation 6 . I want to use this inside of a component not on the navigator . "navigationOptions" is not available in version 6, I tired using "options" instead but that also didn’t work. I want to set the header title dynamically inside of a component. Please help.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can use the navigation.setOptions in the latest react navigation and change the title parameter inside that, like shown below:

useEffect(()=>{
      props.navigation.setOptions({ title: "Title"})
  },[])

Do it inside the component you want to use.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading