首页 文章

React.createElement:type无效

提问于
浏览
0

我是新来的反应和原生的反应 . 我想使用libary来反应原生 . https://github.com/FaridSafi/react-native-gifted-chat但是我收到了这个错误:

警告:React.createElement:type无效 - 期望一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:object . 您可能忘记从其定义的文件中导出组件 . 请在registerRootComponent.js中检查您的代码:21 . 在RCTView(在View.js:128)中的ExponentRootComponent(在renderApplication.js:35)中的视图(在AppContainer.js:93)中的RCTView(在View.js:128)中的视图(在AppContainer.js:92)在AppContainer中(在renderApplication.js:34)

这是我的代码:

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,
        }}
      />
    );
  }

}

我添加这个lib:

yarn add react-native-gifted-chat

我使用Expo-XDE在Android模拟器上启动我的应用程序 .

2 回答

  • 1

    导出 App 组件以进行渲染 .

  • 2

    如警告中所述,您可能忘记从其定义的文件中导出组件 .

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

    App extends React.Component{ ... }
    export default App
    

相关问题