2017-07-17 55 views
0

我是新来对原生做出反应和反应。我想用一个库文件来反应原生。 https://github.com/FaridSafi/react-native-gifted-chat 但我得到这个错误:React.createElement:类型无效

警告:React.createElement:类型无效 - 预期字符串 (用于内置组件)或类/功能(复合 组件),但得到:对象。您可能忘记从其定义的文件中导出您的 组件。

检查您的代码在registerRootComponent.js:21。 在ExponentRootComponent(在renderApplication.js:35) 在RCTView(在View.js:128) 在视图(在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

导出App组件来呈现它。

+0

我都尝试的底部增加一个出口,它不工作 – Xero

+0

您正在导出“应用程序”组件,对吗? –

+0

对不起,它工作了一秒,然后再次崩溃......我添加了这个'导出默认应用程序;'顶部 – Xero

1

正如警告说,你可能忘了您的组件从它的定义文件导出。

只需在文件

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