我是新来的反应和反应本地人。我想用唇语来回应本族语。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)
这里我的代码:
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我使用博览XDE在android仿真器上启动我的应用程序。
发布于 2017-07-17 20:07:33
导出App组件以呈现它。
发布于 2017-07-17 20:20:38
正如警告中所说的,您可能忘记了从定义在其中的文件导出组件。
只需在文件底部添加导出即可。
App extends React.Component{ ... }
export default Apphttps://stackoverflow.com/questions/45152717
复制相似问题