The error “couldn’t find a navigation object. Is your component inside NavigationContainer?” occurs when a component is trying to access a navigation object but it is not wrapped inside a NavigationContainer component. The NavigationContainer is a special component provided by the React Navigation library that manages the navigation state and provides the navigation object to all its child components.
To resolve this issue, you need to make sure that your component is placed inside a NavigationContainer. Here’s an example:
import React from 'react'; import { NavigationContainer } from '@react-navigation/native'; import { createStackNavigator } from '@react-navigation/stack'; import HomeScreen from './screens/HomeScreen'; const Stack = createStackNavigator(); const App = () => { return (); }; export default App;
In the example above, the App component is wrapped inside the NavigationContainer component. This allows the child components, such as HomeScreen, to access the navigation object provided by the NavigationContainer.
By ensuring that your component is wrapped inside a NavigationContainer, you can resolve the “couldn’t find a navigation object” error and enable navigation functionality in your application.