class example extends React.Component {
state = {
data: [],
isLoading: true,
}
componentDidMount() {
fetch('example/url')
.then(response => response.json())
.then(data => this.setState({ data }))
}
render() {
const { isLoading } = this.state
if (isLoading) {
return <div>Загрузка</div>
}
return data.map(item => <div key={item.id}>{item.name}</div>)
}
}