Ad

React Native Router Flux - Expected A Component Class, Got [object Object] When Click A Button To Go To Another Screen

I am getting component class got object error while using react-native-router-flux, Here is my app.js file and component files.

app.js

import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import ScarletScreen from './components/ScarletScreen';
import GrayScreen from './components/GrayScreen';
import {Router, Scene} from 'react-native-router-flux';

const App = () => {

    return (
     <Router>
      <Scene key = "root">

        <Scene
          key = "scarlet"
          component =  {ScarletScreen }
          title = "Scarlet"
          initial
        />


      <Scene
          key = "gray"
          component = { GrayScreen }
          title = "Gray"
        />
      </Scene>

     </Router>
    );
  }

export default App;

ScarletScreen.js

import React, { Component } from 'react';
import { Text, View, Button } from 'react-native';

import { Actions } from 'react-native-router-flux';

const ScarletScreen = () => {
  return (
    <View
      style={{
        backgroundColor: '#bb0000',
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
      }}>
      <Text>Scarlet Screen</Text>

      <Button title="IR PARA GRAY" onPress={() => Actions.gray()} />
    </View>
  );
};

export default ScarletScreen;

GrayScreen.js

import React, { Component } from 'react';
import {Text, View} from 'react-native';

import { Actions } from 'react-native-router-flux';

const GrayScreen = () => {
  return(
    <View style={{backgroundColor: '#666666', flex: 1, alignItems: 'center', justifyContent: 'center'}}>
      <Text>Gray Screen</Text>
    </View>
  );
};

When I click on a button, the error "element type is invalid: expected a string" is shown.

Ad

Answer

You need to ensure all your components are exported. GrayScreen is missing the export.

export default Grayscreen
Ad
source: stackoverflow.com
Ad