2017-07-03 30 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執行環境在需要其他模塊之前被設置。