React Native Router Flux - ожидал класс компонента, получил [объект Object] при нажатии кнопки для перехода на другой экран - PullRequest
0 голосов
/ 23 февраля 2019

Я получаю объектный класс, получивший объектную ошибку при использовании response-native-router-flux. Вот мой файл app.js и файлы компонентов.

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>
  );
};

Когда я нажимаю кнопку, появляется сообщение об ошибке «недопустимый тип элемента: ожидается строка».

1 Ответ

0 голосов
/ 23 февраля 2019

Вы должны убедиться, что все ваши компоненты экспортированы.GrayScreen отсутствует экспорт.

export default Grayscreen
...