Skip to content

Instantly share code, notes, and snippets.

@OlivierJM
Last active August 7, 2018 15:04
Show Gist options
  • Save OlivierJM/2f29a8db9b40dc2a1daf13aff0e468ef to your computer and use it in GitHub Desktop.
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
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