Last active
August 7, 2018 15:04
-
-
Save OlivierJM/2f29a8db9b40dc2a1daf13aff0e468ef to your computer and use it in GitHub Desktop.
use the async and await with axios on multiple request with multiple promises
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
getRemoteData = async () => { | |
try { | |
const coursePromise = axios('http://x.x.x.x/api/course/'); | |
const topicPromise = axios('http://x.x.x.x/api/topic/'); | |
const [ courses, topics ] = await Promise.all(coursePromise, topicPromise]); | |
this.setState({ | |
courses: courses.data.data, | |
topics: topics.data.data, | |
loading: false, | |
}); | |
} catch (error) { | |
this.setState({ | |
error: error.message, | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment