2017-07-28 37 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 –

相关问题