Async/await has come in handy when fetching data asynchronously, especially in the
async componentDidMount() {
try {
const response = await axios.get(endpoints.one)
const data = await response
this.setState({ data, isLoading: false })
} catch (e) {
this.setState({ errors: e.response })
}
}
Moreover, when fetching from multiple endpoints, one can easily use
Promise.all([
fetch(endpoints.one),
fetch(endpoints.two),
]).then(([data1, data2]) => {
console.log(data1, data2)
}).catch((err) => {
console.log(err);
});
However, how can one use aync/await to fetch data from multiples sources instead of Promise.all?