React Native Navigation Issue: The route's component must be a valid React Component

Hello everyone, I am a beginner in the world of React Native and I am currently working on creating a simple navigation system. However, I have encountered an error that I am unable to resolve. Can anyone provide me with some guidance? Click here for the error screenshot that I am seeing on my Samsung S7 Edge running Oreo 8.0.

***Homescreen.js***
import React from "react";
import { Text, StyleSheet } from "react-native";

const HomeScreen = () => {
  return <Text style={styles.text}>Hello World</Text>;
};

const styles = StyleSheet.create({
  text: {
    fontSize: 30
  }
});

***App.js***
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import HomeScreen from './src/screens/HomeScreen'
import ComponentsScreen from './src/screens/ComponentsScreen'

const navigator = createStackNavigator(
  {
    Home: HomeScreen,
    Components:ComponentsScreen
  },
  {
    initialRouteName: 'Components',
    defaultNavigationOptions: {
      title: "App"
    }
  }
);

export default createAppContainer(navigator);

***ComponentsScreen.js***
import React from 'react'
import {Text,StyleSheet} from 'react-native'

const ComponentsScreen=function(){
    return <Text style={styles.textStyle}>This is the Components Screen</Text>
}

const styles=StyleSheet.create({
    textStyle:{
    fontSize:30
    }
})

Answer №1

Your provided code has been tested and it is functioning perfectly. To enhance its functionality, don't forget to add exports in both your HomeScreen and ComponentsScreen:

import React from "react";
import { Text, StyleSheet } from "react-native";

const HomeScreen = () => {
  return <Text style={styles.text}>Hello World</Text>;
};

export default HomeScreen;
const styles = StyleSheet.create({
  text: {
    fontSize: 30
  }
});

ComponentsScreen:

import React from 'react'
import {Text,StyleSheet} from 'react-native'

const ComponentsScreen=function(){
    return <Text style={styles.textStyle}>This is the Components Screen</Text>
}

export default ComponentsScreen;
const styles=StyleSheet.create({
    textStyle:{
    fontSize:30
    }
})

Furthermore, ensure that you have accurately named your components. For instance, you declared a component as Homescreen with a lowercase s, but you are importing it in App.js with a capital S. Please verify this detail.

I trust this information proves helpful!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

android.support.v7.app.ActionBar and android.app.ActionBar are two different classes that can be used for

Having trouble creating an app with tabs? Here's the issue I encountered: When using 'ActionBar actionBar', I received an error at this line of code: actionBar = getActionBar(); -> incompatible type. And when using android.app.Action ...

Moodle API feedback

Is there a way to extract specific data from the API response by targeting a particular response field? var domainname = 'https://sandbox.moodledemo.net'; var token = '234bc817adf979e93f442946c00aa223'; var fu ...

Can someone provide guidance on creating a JavaScript function that locates an image within an <li> element and sets that image as the background-image property in the li's CSS?

Let's dive deeper into this concept: <li class="whatever"> <img src="/images/clients/something.jpg"> </li> <li class="whatever"> <img src="/images/clients/whatever.png"> </li> He ...

Organizing JSON array data with identical values in Android Studio

I need to organize my Json data by grouping it based on the sub_name field in order to create an array of Phone and Mobile Operation. The goal is to have separate arrays with identical data values merged into one. category: { cate: [ { sub_ ...

Manipulating arrays in JavaScript

Currently, I am iterating through an array of waypoints fetched from the Google Maps API. Within this array, I need to retrieve the values labeled Xa and Ya. Right now, I'm accessing these values using [i]["location"]["Xa"], but the labels can vary (e ...

I attempt to use the OBJECT3D array

As a beginner with Three.js, I am trying to add my 'model' object to an array. I believe my code is correct. I have declared my variable as nextobj = [ ];. function Loadobj() { var mx = [-1500,1500] , my = [350,350] , mz = [-1000,-1000]; ...

Is there a way to designate my app as a 'system application' on Android?

I need help with an application that used to update APN settings. Since Android 4.0, this functionality is restricted, but I am wondering: Is there a way to designate my application as a "System app" so it can be installed on non-rooted devices and have a ...

The code encountered an issue: The class THREE.PlaneBufferGeometry cannot be used as a

Help needed! I am facing an error in my code and the console is showing this message: THREE.PlaneBufferGeometry is not a constructor Here is the code snippet: function particleSetup() { let loader = new THREE.TextureLoader() ; loader. load("smo ...

Learn how to automatically navigate to another page upon successfully creating an account and setting a value in the Firebase database

I am working on a system where, after successfully creating an account and setting a value in Firebase database, the user will be redirected to another page. Currently, I have managed to navigate to the next page but I am facing an issue with setting the ...

What is the mechanism behind the clipping function in the three.js frustum?

Currently, I am exploring the frustum feature of three.js by making changes to the example provided in the Scene Graph section here. function main() { const canvas = document.querySelector('#c'); const renderer = new THREE.WebGLRenderer({c ...

Android hardware button press to navigate back in JQuery Mobile

Could someone please provide an example of how to listen for the hardware back button press event on a specific page in an Android device? I have tried the following code but it doesn't seem to be working: $(document).on('pageshow', functi ...

When a function is called, retrieve a specific number of elements from an array using the slice method in

If I have an array of 15 objects, but I am only displaying 5 on the browser using this code: const displayedArray = array.slice(0,4) I also have a function that will load another 5 objects each time a user scrolls down. displayedArray.concat(array.slice ...

When using $http.get, it retrieves source code instead of displaying HTML content

Just diving into the world of AngularJS. I am using the $http service to make a request for an HTML page from localhost. However, instead of getting the desired result, I'm seeing the source code of the page. http_service.html <!DOCTYPE html> ...

Troubleshooting: Angular input binding issue with updating

I am currently facing a challenge with connecting a list to an input object in Angular. I was expecting the updated values to reflect in the child component every time I make changes to the list, but strangely, the initial values remain unchanged on the sc ...

Unable to assign multiple values to a bootstrap select from an array

Currently, I am dealing with a string: 93, 94 which represents the references of the values in a select option. My attempt to assign these values using: let values = "93, 94"; $('#property-categories').selectpicker('val', values); ha ...

Difficulty arises when attempting to run code when a checkbox is not selected

In my form validation process, I am facing an issue where I need to validate certain values only if a checkbox is unchecked. If the checkbox is checked, I want to use the values that were previously added. However, none of the existing code snippets seem t ...

Vue Component Failing to Render Recursively

Currently, I am in the process of developing an application utilizing vue.js and vue-cli. This specific application allows users to configure orders. The main feature I am working on is giving users the option to either proceed with configuring another ord ...

Prevent CSS background resize caused by toggling the Chrome URL bar on Android devices

When browsing a website using Chrome for Android, the height of the view area changes when scrolling causes the URL bar to hide. This can lead to annoying resizing of a fixed background image, especially when scrolling down and back up again. https://i.ss ...

Finding the final day of a specific year using the moment library

When it comes to determining the last day of a year, hard-coding the date as December 31st seems like a simple solution. While there are various methods using date, js, and jquery, I am tasked with working on an Angular project which requires me to use mom ...

Increasing the sms counter in javascript once it reaches 160 characters

I am facing an issue with my two counters that are used to track the number of characters in a message. Everything works fine until 160 characters, but after that point, the first counter stops at 0 instead of resetting back to 160 and decreasing from ther ...