Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@mech mech commented Jul 20, 2016

Should be this.state.fetching instead.

@tiendq

This comment has been minimized.

Copy link

@tiendq tiendq commented Oct 18, 2016

The same for this.props.error :)

@SimplGy

This comment has been minimized.

Copy link

@SimplGy 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