React.createElement: type is invalid on Expo

落爺英雄遲暮 提交于 2019-12-24 06:44:58

问题


I'm just starting to learn React Native and I tried to do RN on Expo. Now I'm getting this error.

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.

My code is

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

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


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

I worte this cod on the App.js file


回答1:


You can do like this:

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 );


来源:https://stackoverflow.com/questions/45365211/react-createelement-type-is-invalid-on-expo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!