Error: Couldn't register the navigator. Have you wrapped your app with 'NavigationContainer'?
I am learning to code with this video https://youtu.be/1hPgQWbWmEk , I did exactly what the guy did, but when I run expo start and then go to run in web browser what appears is this error:
Couldn't register the navigator. Have you wrapped your app with 'NavigationContainer'?
Here's my code until now
import { StatusBar } from 'expo-status-bar';
import * as React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import {navigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import { createMaterialTopTabNavigator } from 'react-navigation-tabs'
import LandingScreen from './Components/auth/landing';
const Stack = createStackNavigator();
export default function App() {
return (
<navigationContainer>
<Stack.Navigator initialRouteName="Landing">
<Stack.Screen name="Landing" component={LandingScreen} options={{headerShown: false}}/>
</Stack.Navigator>
</navigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
I know that if I erase this part the code doesn't show any errors
<Stack.Navigator initialRouteName="Landing">
<Stack.Screen name="Landing" component={LandingScreen} options={{headerShown: false}}/>
</Stack.Navigator>
By the way, the code referred to in ./Components/auth/landing is this:
import React from 'react';
import { Text, View, Button} from 'react-native';
export default function Landing({navigation}) {
return (
<View style={{ flex: 1, justifyContent: 'center'}}>
<Button
title="Register"
onPress={() => navigator.navigate("Register")}/>
<Button
title="Login"
onPress={() => navigator.navigate("Login")}/>
</View>
)
}
There is a typo in your code it must be NavigationContainer
instead of navigationContainer
.
import { NavigationContainer } from '@react-navigation/native';
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Landing">
<Stack.Screen name="Landing" component={LandingScreen} options={{headerShown: false}}/>
</Stack.Navigator>
</NavigationContainer>
);
}