React Native Router Flux-需要一个组件类,单击按钮转到另一个屏幕时出现[object Object]

时间:2019-02-23 16:20:13

标签: android ios react-native react-native-router-flux

使用react-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 :(得分:0)

您需要确保所有组件都已导出。 GrayScreen缺少导出。

export default Grayscreen