Here is the full error: ERROR Error: A navigator can only contain ‘Screen’, ‘Group’ or ‘React.Fragment’ as its direct children (found ‘ ‘). To render this component in the navigator, pass it in the ‘component’ prop to ‘Screen’.
This error is located at:
in StackNavigator (created by StackNavigator)
in StackNavigator (created by App)
in EnsureSingleNavigator
in BaseNavigationContainer
in ThemeProvider
in NavigationContainerInner (created by App)
in App (created by withDevTools(App))
in withDevTools(App)
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent)
app.js
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import RegisterScreen from './screens/register';
import LoginScreen from './screens/login';
import SearchScreen from './screens/search';
import DeleteScreen from './screens/delete'; // Import the DeleteScreen component
import firebase from 'firebase';
import { firebaseConfig } from './config';
import MainTabNavigator from './navigation/tabNavigator';
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
} else {
firebase.app();
}
const Stack = createStackNavigator();
const StackNavigator = () => {
return (
<Stack.Navigator screenOptions={{ headerShown: false }} initialRouteName={'Dashboard'}>
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="Register" component={RegisterScreen} />
<Stack.Screen name="Dashboard" component={MainTabNavigator} />
</Stack.Navigator>
);
};
export default function App() {
return (
<NavigationContainer>
<StackNavigator />
</NavigationContainer>
);
}
tabNavigator.js
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import SearchScreen from '../screens/search';
import DeleteScreen from '../screens/delete';
const Tab = createBottomTabNavigator();
export default class MainTabNavigator extends React.Component {
render()
{return (
<Tab.Navigator>
<Tab.Screen name="Search" component={SearchScreen} />
<Tab.Screen name="Delete" component={DeleteScreen} />
</Tab.Navigator>
);}
};
2
Answers
I just wrote the function in app.js
Here is how I have done the above scenario:
Try this way keeping both navigators in a common file, and then use it in App.js like this: