Last active
September 1, 2018 10:06
-
-
Save leopard627/0711a32490fcc7e49dd1c1c011f7ae3e to your computer and use it in GitHub Desktop.
react async fetch data from API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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