在React native

时间:2017-07-03 00:58:19

标签: reactjs react-native

THE ERROR MESSAGE I AM GETTING ON MY DEVICE我正在研究React Native。我将其他反应原生文件(即component1.js)导入index.android.js文件。 它给出了一个错误 "预期组件类,得到[对象对象]"。

component1.js

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

  export default class component1 extends Component {
      render() {
        return( 
           <View>
             <Text>This is component1</Text>
           </View>
        );
      } 
  }

  AppRegistry.registerComponent('component1', () => component1);

index.android.js

  import React, { Component } from 'react';
  import {AppRegistry,Text,View} from 'react-native';
  import component1 from'./app/Components/component_a/component1'

  export default class myapp extends Component {
      render() {
           return (
                 <View>
                     <component1 />
                  </View>
           );
      }
  }

  AppRegistry.registerComponent('myapp', () => myapp);

1 个答案:

答案 0 :(得分:1)

问题是您在子文件和父文件中定义了多个AppRegistry。删除component1.js中的AppRegistry.registerComponent('component1', () => component1);,您不需要它。只需在根组件中声明即可。

来自RN文档。

  

应在需求序列的早期要求AppRegistry,以确保在需要其他模块之前设置JS执行环境。

相关问题