Ich bin neu in reagieren-native, ist hier mein Code:einfache api Beispiel holen nicht funktioniert
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);
Und hier wird das Protokoll Fehler:
10:53:38 PM: Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in. Check the render method of
AwakeInDevApp
. in AwakeInDevApp (at registerRootComponent.js:36) in RootErrorBoundary (at registerRootComponent.js:35) in ExpoRootComponent (at renderApplication.js:35) in RCTView (at View.js:113) in View (at AppContainer.js:102) in RCTView (at View.js:113) in View (at AppContainer.js:126) in AppContainer (at renderApplication.js:34) - node_modules/fbjs/lib/warning.js:33:20 in printWarning - ... 24 more stack frames from framework internals