5

Is there any way I could access navigator-screen options object inside Home component ?

    <Stack.Navigator>
        <Stack.Screen
            name="Home"
            component={Home}
            options={
                {
                    /** some options... */
                }
            }
        />
        <Stack.Screen name="About" component={About} />
    </Stack.Navigator>

Home

function Home() {
    /** Get options object here */
    return (
        /** some jsx */
    );
}

I'm using react-navigation 5

Hend El-Sahli
  • 6,268
  • 2
  • 25
  • 42

1 Answers1

-4

you can use navigation.setOptions for your home screen

function Home({ navigation, route }) {
  React.useLayoutEffect(() => {
    navigation.setOptions({ headerTitle: getHeaderTitle(route) });
  }, [navigation, route]);
}

for more detals you can read this documentation screen options

shammi
  • 1,301
  • 1
  • 10
  • 25
  • 1
    Thank you for your answer ... but I have no issue with setting `options` ... The issue is how to retrieve these options inside `Home` – Hend El-Sahli Jun 05 '21 at 12:03