I'm trying to fetch data from two different APIs and want this to happen in parallell but then I want to wait for them to execute and then continue with the next line of code.
componentDidMount() {
this._isMounted = true;
this.fetch1() // <-- Async method
this.fetch2() // <-- Async method
this.func(); // The above two lines of code needs to be done to execute this line
}
async fetch1() {
fetch("/api/abc123")
.then(res => res.json())
.then(res => {
this.setState({ foo: res });
});
}
async fetch2() {
fetch("/api/def456")
.then(res => res.json())
.then(res => {
this.setState({ bar: res });
});
}
func() {
// Do something with the data from the APIs
}