我是react native的新手,以下是我的代码:
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
class FetchExample extends Component {
constructor() {
super();
this.state = {
date: ''
}
}
render() {
return (
<View style={styles.container}>
<Text>{}</Text>
</View>
);
}
componentWillMount() {
fetch("http://date.jsontest.com/")
.then((response) => response.json())
.then((responseData) => {
console.log('a');
this.setState({date: responseData.date});
})
.done();
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
}
});
AppRegistry.registerComponent('ak', () => FetchExample);
下面是日志错误:
10: 下午53:38:警告:反应。createElement:类型无效--应为
字符串(用于内置组件)或类/函数(用于复合
组件),但得到:对象。您可能忘记导出
它在中定义的文件中的组件。检查的渲染方法
AwakeInDevApp
.
在AwakeInDevApp中(位于registerRootComponent.js:36)
在RootErrorBoundary中(在registerRootComponent.js:35处)
在ExprootComponent中(在renderApplication.js:35)
在RCTView中(在视图中。js:113)
在视图中(位于AppContainer.js:102)
在RCTView中(在视图中。js:113)
在视图中(在AppContainer.js:126)
在AppContainer中(在renderApplication.js:34)
-node\u modules/fbjs/lib/warning。打印警告中的js:33:20
- ... 框架内部的24个堆叠框架