I'm getting this error after updating My navigation to navigation 6
It's telling me "Check the render method of ProductsNavigator
"
and im not even exporting the ProductsNavigator I'm putting it in the drawer and I'm exporting the drawer instead ! can you guys tell me where is the problem here ?
App.js
import { StatusBar } from "expo-status-bar";
import { StyleSheet } from "react-native";
import { createStore, combineReducers, applyMiddleware } from "redux";
import { Provider } from "react-redux";
import AppLoading from "expo-app-loading";
import * as Font from "expo-font";
import productsReducer from "./store/reducers/products";
import { composeWithDevTools } from "redux-devtools-extension";
import cartReducer from "./store/reducers/cart";
import { useState } from "react";
import ordersReducer from "./store/reducers/orders";
import AuthReducer from "./store/reducers/Auth";
import ReduxThunk from "redux-thunk";
import AppNavigator from "./navigation/NavigationContainer";
const rootReducer = combineReducers({
products: productsReducer,
cart: cartReducer,
orders: ordersReducer,
auth: AuthReducer,
});
const store = createStore(
rootReducer,
applyMiddleware(ReduxThunk),
composeWithDevTools()
);
const fetchFonts = () => {
return Font.loadAsync({
"open-sans": require("./assets/fonts/OpenSans-Regular.ttf"),
"open-sans-bold": require("./assets/fonts/OpenSans-Bold.ttf"),
});
};
export default function App() {
const [fontLoaded, setfontLoaded] = useState(false);
if (!fontLoaded) {
return (
<AppLoading
startAsync={fetchFonts}
onFinish={() => setfontLoaded(true)}
one rror={console.warn}
/>
);
}
return (
<Provider store={store}>
<AppNavigator />
</Provider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
Navigation Container
import React from "react";
import { useSelector } from "react-redux";
import { NavigationContainer } from "@react-navigation/native";
import { ShopNavigator, AuthNavigator } from "./ShopNavigation";
import StartUpScreen from "../screens/StartUpScreen";
const AppNavigator = (props) => {
const isAuth = useSelector((state) => !!state.auth.token);
const didTryAutoLogin = useSelector((state) => state.auth.didTryAutoLogin);
return (
<NavigationContainer>
{isAuth && <ShopNavigator />}
{!isAuth && didTryAutoLogin && <AuthNavigator />}
{!isAuth && !didTryAutoLogin && <StartUpScreen />}
</NavigationContainer>
);
};
export default AppNavigator;
The App navigator
import React from "react";
import { createStackNavigator } from "@react-navigation/stack";
import { useDispatch } from "react-redux";
import ProductsOverviewScreen, {
screenOptions as productsOverviewScreenOptions,
} from "../screens/shop/ProductsOverviewScreen";
import ProductDetails, {
screenOptions as productDetailScreenOptions,
} from "../screens/shop/ProductDetailScreen";
import CartScreen, {
screenOptions as cartScreenOptions,
} from "../screens/shop/CartScreen";
import OrdersScreen, {
screenOptions as ordersScreenOptions,
} from "../screens/shop/OrdersScreen";
import {
createDrawerNavigator,
DrawerContentScrollView,
DrawerItemList,
} from "@react-navigation/drawer";
import userProducts, {
screenOptions as userProductsScreenOptions,
} from "../screens/user/UserProductsScreen";
import EditingProductScreen, {
screenOptions as editProductScreenOptions,
} from "../screens/user/EditProductScreen";
import AddingProductScreen, {
screenOptions as AddingProductScreenOptions,
} from "../screens/user/AddingProductScreen";
import { Button, Platform } from "react-native";
import Login from "../screens/Auth/login";
import * as authActions from "../store/actions/Auth";
import { Ionicons } from "@expo/vector-icons";
const ProductsStackNavigator = createStackNavigator();
const defaultNavOptions = {
headerStyle: {
backgroundColor: Platform.OS === "android" ? "aqua" : "",
},
headerTitleStyle: {
fontFamily: "open-sans-bold",
},
headerBackTitleStyle: {
fontFamily: "open-sans",
},
headerTintColor: Platform.OS === "android" ? "white" : "aqua",
};
const ProductsNavigator = () => {
return (
<ProductsStackNavigator screenOptions={defaultNavOptions}>
<ProductsStackNavigator.Screen
name="ProductsOverview"
component={ProductsOverviewScreen}
options={productsOverviewScreenOptions}
/>
<ProductsStackNavigator.Screen
name="ProductsDetail"
component={ProductDetails}
options={productDetailScreenOptions}
/>
<ProductsStackNavigator.Screen
name="CartScreen"
component={CartScreen}
options={cartScreenOptions}
/>
</ProductsStackNavigator>
);
};
const OrdersStackNavigator = createStackNavigator();
export const OrdersNavigator = () => (
<OrdersStackNavigator.Navigator screenOptions={defaultNavOptions}>
<OrdersStackNavigator.Screen name="OrdersScreen" component={OrdersScreen} />
</OrdersStackNavigator.Navigator>
);
const AdminStackNavigator = createStackNavigator();
export const AdminNavigator = () => (
<AdminStackNavigator.Navigator screenOptions={defaultNavOptions}>
<AdminStackNavigator.Screen
name="User Products"
component={userProducts}
options={userProductsScreenOptions}
/>
<AdminStackNavigator.Screen
name="EditingProductScreen"
component={EditingProductScreen}
options={editProductScreenOptions}
/>
<AdminStackNavigator.Screen
name="AddingProductScreen"
component={AddingProductScreen}
options={AddingProductScreenOptions}
/>
</AdminStackNavigator.Navigator>
);
function CustomDrawerContent(props) {
const dispatch = useDispatch();
return (
<DrawerContentScrollView {...props}>
<DrawerItemList {...props} />
<Button
title="LOGOUT"
onPress={() => {
dispatch(authActions.logout());
}}
/>
</DrawerContentScrollView>
);
}
const ShopDrawerNavigator = createDrawerNavigator();
export const ShopNavigator = () => {
return (
<ShopDrawerNavigator.Navigator
drawerContentOptions={{
activeTintColor: "aqua",
}}
drawerContent={(props) => <CustomDrawerContent {...props} />}
>
<ShopDrawerNavigator.Screen
name="Products"
component={ProductsNavigator}
options={{
drawerIcon: (props) => (
<Ionicons
name={Platform.OS === "android" ? "md-cart" : "ios-cart"}
size={23}
color="aqua"
/>
),
}}
/>
<ShopDrawerNavigator.Screen
name="Orders"
component={OrdersNavigator}
options={{
drawerIcon: (props) => (
<Ionicons
name={Platform.OS === "android" ? "md-list" : "ios-list"}
size={23}
color="aqua"
/>
),
}}
/>
<ShopDrawerNavigator.Screen
name="Admin"
component={AdminNavigator}
options={{
drawerIcon: (props) => (
<Ionicons
name={Platform.OS === "android" ? "md-create" : "ios-create"}
size={23}
color="aqua"
/>
),
}}
/>
</ShopDrawerNavigator.Navigator>
);
};
const AuthStackNavigator = createStackNavigator();
export const AuthNavigator = () => (
<AuthStackNavigator.Navigator
screenOptions={({}) => ({ headerShown: false })}
>
<AuthStackNavigator.Screen name="Login" component={Login} />
</AuthStackNavigator.Navigator>
);
CodePudding user response:
I believe you are missing to add .Navigator to your ProductsNavigator component
const ProductsNavigator = () => {
return (
<ProductsStackNavigator.Navigator screenOptions={defaultNavOptions}>
<ProductsStackNavigator.Screen
name="ProductsOverview"
component={ProductsOverviewScreen}
options={productsOverviewScreenOptions}
/>
<ProductsStackNavigator.Screen
name="ProductsDetail"
component={ProductDetails}
options={productDetailScreenOptions}
/>
<ProductsStackNavigator.Screen
name="CartScreen"
component={CartScreen}
options={cartScreenOptions}
/>
</ProductsStackNavigator.Navigator>
);
};