Skip to content

Instantly share code, notes, and snippets.

@samzhao samzhao/index.js
Last active Jun 30, 2018

Embed
What would you like to do?
Simple Async/await Example
import axios from 'axios';
const API_URL = "https://jsonplaceholder.typicode.com/posts/1";
// Before async/await
const logPostId = () => {
axios.get(API_URL)
.then(resp => {
const { data } = resp;
const { id } = data;
console.log('Post Id:', id);
});
}
logPostId(); // Post Id: 1
// After async/await
const logPostId = async () => {
const { data } = await axios.get(API_URL);
const { id } = data;
console.log('Post Id:', id);
}
logPostId(); // Post Id: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.