import React from 'react'; import ReactDOM from 'react-dom'; import fetch from 'isomorphic-fetch' class PeopleList extends React.Component { constructor(props) { super(props) this.state = { data: [], loaded: true, loading: false } } componentDidMount() { //this.setState({loading:true}) fetch('https://randomuser.me/api/?results=100') .then(response => response.json()) .then(obj => obj.results) .then(data => this.setState({ loaded: true, loading: false, data })) } render() { const { data, loading } = this.state return (loading) ? <div>Loading...</div> : <ol className="people-list"> {data.map((person, i) => { const {first, last} = person.name return <li key={i}>{first} {last}</li> })} </ol> } } ReactDOM.render(<PeopleList />, document.getElementById('root'));