首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React.createElement:类型无效

React.createElement:类型无效
EN

Stack Overflow用户
提问于 2017-07-17 20:02:35
回答 2查看 1.9K关注 0票数 0

我是新来的反应和反应本地人。我想用唇语来回应本族语。https://github.com/FaridSafi/react-native-gifted-chat,但我得到了一个错误:

警告: React.createElement: type无效--需要一个字符串(用于内置组件)或一个类/函数(用于复合组件),但是got: object。您可能忘记从定义在其中的文件中导出组件。 检查您在registerRootComponent.js:21的代码。ExponentRootComponent (at renderApplication.js:35) in RCTView (at View.js:128) in View (at AppContainer.js:93) in RCTView (at View.js:128) in View (at AppContainer.js:92) in AppContainer (at renderApplication.js:34)

这里我的代码:

代码语言:javascript
复制
import React from 'react';
import { StyleSheet, Text, View, KeyboardAvoidingView, Image, TextInput } from 'react-native';
import GiftedChat from 'react-native-gifted-chat';

class App extends React.Component {

  state = {
    messages: [],
  };


  componentWillMount() {
    this.setState({
      messages: [
        {
          _id: 1,
          text: 'Hello developer',
          createdAt: new Date(),
          user: {
            _id: 2,
            name: 'React Native',
            avatar: 'https://facebook.github.io/react/img/logo_og.png',
          },
        },
      ],
    });
  }

  onSend(messages = []) {
    this.setState((previousState) => ({
      messages: GiftedChat.append(previousState.messages, messages),
    }));
  }

  render() {
    return (
      <GiftedChat
        messages={this.state.messages}
        onSend={(messages) => this.onSend(messages)}
        user={{
          _id: 1,
        }}
      />
    );
  }

}

我将这个库添加到:

代码语言:javascript
复制
yarn add react-native-gifted-chat

我使用博览XDE在android仿真器上启动我的应用程序。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-17 20:07:33

导出App组件以呈现它。

票数 2
EN

Stack Overflow用户

发布于 2017-07-17 20:20:38

正如警告中所说的,您可能忘记了从定义在其中的文件导出组件。

只需在文件底部添加导出即可。

代码语言:javascript
复制
App extends React.Component{ ... }
export default App
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45152717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档