Skip to content

Instantly share code, notes, and snippets.

@marharyta
Created July 17, 2018 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marharyta/23c4450df426253c7c1e753db3418ed6 to your computer and use it in GitHub Desktop.
Save marharyta/23c4450df426253c7c1e753db3418ed6 to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDOM from 'react-dom';
import './css/main.css';
class App extends React.Component {
constructor(props) {
super(props);
this.state = { coworkings: [] };
}
componentDidMount() {
fetch('https://api.myjson.com/bins/nwxou', {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
})
.then(res => res.json())
.then(res => {
console.log(res);
this.setState({ coworkings: res.coworkings });
})
.catch(error => {
console.log(error);
});
}
render() {
return (
<ul>
{this.state.coworkings.map(i => {
return <li key={i.id}>{i.title} </li>;
})}
</ul>
);
}
}
const rootElement = document.getElementById('root');
ReactDOM.render(<App />, rootElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment