【发布时间】:2018-05-22 00:00:29
【问题描述】:
我是 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 PM:警告:React.createElement:类型无效——预期 字符串(用于内置组件)或类/函数(用于复合 组件)但得到:对象。您可能忘记导出您的 组件从它定义的文件中。检查渲染方法
AwakeInDevApp。 在 AwakeInDevApp 中(在 registerRootComponent.js:36) 在 RootErrorBoundary 中(在 registerRootComponent.js:35 处) 在 ExpoRootComponent 中(在 renderApplication.js:35) 在 RCTView 中(在 View.js:113) 在视图中(在 AppContainer.js:102) 在 RCTView 中(在 View.js:113) 在视图中(在 AppContainer.js:126) 在 AppContainer 中(在 renderApplication.js:34 处) - printWarning 中的 node_modules/fbjs/lib/warning.js:33:20 - ... 来自框架内部的另外 24 个堆栈帧
【问题讨论】:
标签: reactjs react-native fetch-api