Skip to content
Advertisement

Nested Navigation in React Native not compiling

I’m new to nested navigation. I have tried to follow the principles here – however I am getting the error

Couldn’t find a navigation object. Is your component inside NavigationContainer?

I have brought the ‘Screens’ into the main App.js for ease of debugging and sharing code. Below is my code.

I am trying to have a home screen with a Nav Drawer, on two of the screens (‘Patterns’ and ‘One Step’) I’m then trying to implement Stacked Navigation as they will have lists and detail screens within.

JavaScript

Advertisement

Answer

You are calling useNavigation before you define NavigationContainer, that should not work. Make component, for example <AppNavigator /> as a children of NavigationContainer, then try to build your navigation in that component.

JavaScript

And your NavigationContainer is also fairly confusing to me. So you either can have screens in your parent navigator or another navigators.

this is CORRECT:

JavaScript

I would rename this, as you are trying to have StackNavigator here:

JavaScript

to something like this example:

JavaScript

And then in OneStepStack(former oneStepScreen) you can’t have normal JSX mixed with Stack.Navigator.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement