Skip to content

Instantly share code, notes, and snippets.

@eklitzke
Created January 6, 2019 21:08
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 eklitzke/d558f75fbd21ec1c3d44b9f8546913ab to your computer and use it in GitHub Desktop.
Save eklitzke/d558f75fbd21ec1c3d44b9f8546913ab to your computer and use it in GitHub Desktop.
// App.js
import React, { Component } from 'react';
class App extends Component {
state = {
todos: []
};
async componentDidMount() {
try {
const res = await fetch('http://127.0.0.1:8000/api/');
const todos = await res.json();
this.setState({
todos
});
} catch (e) {
console.log(e);
}
}
render() {
return (
<div>
{this.state.todos.map(item => (
<div key={item.id}>
<h1>{item.title}</h1>
<span>{item.description}</span>
</div>
))}
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment