How does one get screen options from within a component in react navigation v5?

Viewed 923

I dynamically set the "headerShown" screen option but I can't sort out how to read the options from within a functional component

<Stack.Navigator
    screenOptions={{
      headerShown: showHeader
}}>

Ive tried the navigation, route and state objects from within the component using useNavigation, useRoute and useNavigationState respectively and none seem to have a way to get the screen option values.

1 Answers

if your component is a screen, you can access the options of screen by doing this

function MyComponent({scene}) {
    console.log(scene.descriptor.options);
}
Related