Created
June 21, 2016 16:15
-
-
Save osmelmora/bfcdb7cf23bc53c2a8c058f628b2ed8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Container = React.createClass({ | |
getInitialState: function() { | |
return { | |
data: null, | |
fetching: false, | |
error: null | |
}; | |
}, | |
render: function() { | |
if (this.props.fetching) { | |
return <div>Loading...</div>; | |
} | |
if (this.props.error) { | |
return ( | |
<div className='error'> | |
{this.state.error.message} | |
</div> | |
); | |
} | |
return <Counter {...data} /> | |
}, | |
componentDidMount: function() { | |
this.setState({fetching: true}); | |
Axios.get(this.props.url).then(function(res) { | |
this.setState({data: res.data, fetching: false}); | |
}).catch(function(res) { | |
this.setState({error: res.data, fetching: false}); | |
}); | |
} | |
}); |
The same for this.props.error :)
and return <Counter {...data} />
:)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should be
this.state.fetching
instead.