1

I'm new in react-native,Here is my code:

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);

And here is the log Error:

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

Screenshot

1 Answer 1

2

You'll need to export your component. like this

export default class FetchExample extends Component {
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.