2017-07-17 14 views
0

私は反応してネイティブに反応します。私は、反応したネイティブのための図書館を使いたい。 https://github.com/FaridSafi/react-native-gifted-chat しかし、私はこのエラーを得た:React.createElement:タイプが無効です

警告:React.createElement:タイプが無効です - 予想(内蔵部品のための)文字列 か(複合 コンポーネントの)クラス/関数ではなくなりました:オブジェクト。 コンポーネントを定義したファイルからエクスポートするのを忘れた可能性があります。

registerRootComponent.js:21でコードを確認してください。 RCTViewで (View.js時:128)(93 AppContainer.jsで) ビューで:RCTViewで (128 View.jsで):(35 renderApplication.jsで)ExponentRootComponentで ビューで(AppContainerで.js:renderApplication.jsでAppContainer 92) (:34)

ここに私のコード:

yarn add react-native-gifted-chat 

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を追加します

私はAndroidのエミュレータで私のアプリを起動するためにExpo-XDEを使用します。

答えて

2

Appコンポーネントをエクスポートしてレンダリングします。

+0

で輸出を追加doesntのwork – Xero

+0

あなたは 'App'コンポーネントをエクスポートしていますよね? –

+0

申し訳ありませんが、もう一度クラッシュしてしまいました...この「デフォルトのアプリをエクスポート」を追加しました。トップに戻る – Xero

1

として、あなたはそれがで定義されていたファイルからコンポーネントをエクスポートするのを忘れそうな、警告の中で述べている。

私は、両方を試してみましたちょうどあなたのファイルの一番下

App extends React.Component{ ... } 
export default App 
関連する問題