【发布时间】:2017-12-22 11:47:45
【问题描述】:
我是新来的反应和反应本机。我想使用一个库来反应原生。 https://github.com/FaridSafi/react-native-gifted-chat 但是我收到了这个错误:
警告: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,
}}
/>
);
}
}
我添加这个库:
yarn add react-native-gifted-chat
我使用 Expo-XDE 在 android 模拟器上启动我的应用程序。
【问题讨论】:
标签: reactjs react-native