Skip to content

Instantly share code, notes, and snippets.

@leopard627
Last active September 1, 2018 10:06
Show Gist options
  • Save leopard627/0711a32490fcc7e49dd1c1c011f7ae3e to your computer and use it in GitHub Desktop.
Save leopard627/0711a32490fcc7e49dd1c1c011f7ae3e to your computer and use it in GitHub Desktop.
react async fetch data from API
import React, { Component } from "react";
import axios from "axios";
class Posts extends Component {
state = {
posts: []
};
async componentDidMount() {
const response = await axios.get("http://localhost:8000/posts");
console.log(response);
}
render() {
return <h1>hello world</h1>;
}
}
export default Posts;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment