1

My App.js file code is like this

import { createAppContainer } from "react-navigation";
import { createStackNavigator } from "react-navigation-stack";
import IndexScreen from "./src/screen/IndexScreen";
const navigator = createStackNavigator({
  Home: {
    screen: IndexScreen
  }
});

export default createAppContainer(navigator);

And my index.js file is like

import { React } from "react";
import { View, Text, StyleSheet } from "react-native";
const IndexScreen = () => {
  return (
    <View>
      <Text>IndexScreeen</Text>
    </View>
  );
};
const styles = StyleSheet.create({});

export default IndexScreen;

But after running the application I am getting this error. enter image description here

What is my mistake

1
  • Have you tried to create IndexScreen as a class that extends React.Component and have a function render() inside? Also, your file is named index.js and you are trying to import file IndexScreen ? Commented Nov 12, 2019 at 18:12

3 Answers 3

3

You are importing import IndexScreen from "./src/screen/IndexScreen"; and you said your file is named as index.js, is that right?

By the way, I get an error when I try import { React } from "react";. However if I try import React from "react"; it works.

Sign up to request clarification or add additional context in comments.

2 Comments

no I have made a mistake in the question actually file name is IndexScreen.js and I have used your suggestion of importing React insted of {React} but still face the same issue.
@Utpal if you made mistake on the question, then edit it and fix, to avoid people answering you with wrong solutions caused by your mistaken code...
1

Finally solve it , actually I made a mistake to define a function component just after the import without adding a line break or blank line.

Comments

1

Three things:

  1. You are importing IndexScreen, instead of index.js

  2. It's not import { React } from "react";. It's import React from "react";

  3. You are using const to Export from the file. The Export to use it as a react component you should probably do :

    class IndexScreen extends React.Component {
        render() {return (
            <View>
                <Text>IndexScreeen</Text>
            </View>
          );
        }
    }

3 Comments

no I have made a mistake in the question actually file name is IndexScreen.js and I have used your suggestion of importing React insted of {React} but still face the same issue.
have you tried removing node_modules files and installing it again? Maybe it will help you know.
Ahh, I think I found the issue. You are not using react Component to output. I will update my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.