Major Porcelana
Major Porcelana

Reputation: 11

"Error: Creating a navigator doesn't take an argument."

I am trying to create a navigation bar for my application in react native. After a day with the application running normally, I opened it and then I came across this error: "Error: Creating a navigator doesn't take an argument.". I hoped someone could help me so that I can proceed. Here is my code:

import React from "react";
import {Text, StyleSheet} from "react-native";
import {createAppContainer} from "@react-navigation/native";

import {createStackNavigator} from "@react-navigation/stack";

import Feed from "./src/screens/Feed/matrix";

const MainNavigator = createStackNavigator(
{
    Feed
},
{
    defaultNavigationOptions: {
        headerTitle: <Text>๐“จ๐“ฎ๐“ผ๐“ฑ๐“พ๐“ช๐“น๐“น</Text>,
    }
});

export default createAppContainer(MainNavigator); '''

Upvotes: 1

Views: 1332

Answers (1)

HichamELBSI
HichamELBSI

Reputation: 1719

This error is trigger when you pass a param to the createStackNavigator() function.

With react-navigation 5, you can create the stack navigator just like that:

import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

onst Stack = createStackNavigator();

const FirstScreenComponent = () => <View><Text>First screen</Text></View>

const SecondScreenComponent = () => <View><Text>Sezcond screen</Text></View>

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="First screen" component={FirstScreenComponent} />
        <Stack.Screen name="Second screen" component={SecondScreenComponent} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

export default App;

If you still want to use it with function (on your example), I think you should downgrade react-navigation to the v4.

Tell me if it solves your problem.

Upvotes: 1

Related Questions