Skip to content

Instantly share code, notes, and snippets.

@osmelmora
Created June 21, 2016 16:15
Show Gist options
  • Save osmelmora/bfcdb7cf23bc53c2a8c058f628b2ed8e to your computer and use it in GitHub Desktop.
Save osmelmora/bfcdb7cf23bc53c2a8c058f628b2ed8e to your computer and use it in GitHub Desktop.
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});
});
}
});
@mech
Copy link

mech commented Jul 20, 2016

Should be this.state.fetching instead.

@tiendq
Copy link

tiendq commented Oct 18, 2016

The same for this.props.error :)

@SimplGy
Copy link

SimplGy commented Jul 11, 2017

and return <Counter {...data} /> :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment