2017-07-28 39 views
1

我剛開始學習React Native,我試圖在世博會上做RN。現在我收到這個錯誤。React.createElement:類型在世博會上無效

Warning: React.createElement: type is invalid -- expected a string (for 
built-in components) or a class/function (for composite components) 
but got: object. You likely forgot to export your component from the 
file it's defined in. 

我的代碼是

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

const App =() => (
    <Text>Some Text </Text> 
    ); 


AppRegistry.registerComponent('helloworld',() => App); 

我又寫道在App.js這個鱈魚文件

回答

1

你可以這樣做:

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

export default class App extends Component { 
    render() { 
    return (
     <Text>Hello world!</Text> 
    ); 
    } 
} 


AppRegistry.registerComponent('helloworld',() => App); 
+0

我寫的代碼是錯了?我實際上是從教程中獲取了這些代碼。 –

+0

從哪個教程? –

+0

https://www.udemy.com/the-complete-react-native-and-redux-course/?altsc=610300 –

相關問題