class MyComponent extends React.Component {
state = {
loading: true,
data: null
}
componentDidMount () {
const data = await fetch(/* ... */);
this.setState({ loading: false, data });
}
render () {
const { data, loading } = this.state;
if (loading) {
return <div className='loading' />
}
return this.renderData(data);
}
}