2017-07-03 204 views
0

THE ERROR MESSAGE I AM GETTING ON MY DEVICE Iam正在处理React Native.As我将其他反应本机文件(即component1.js)导入到index.android.js文件中。 它给出了一个错误 “预计组件类,得到[对象对象]”。在React本机中导入和导出文件

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

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

来自RN docs。

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