I'm working on a React app, and I need to fetch some data when the component mounts. Since I need to make 3 different calls, I thought it would be better to use Promise.all in order to do it in a parallel fashion. The code down here works perfectly fine, it does exactly what I intend it to do, however, the person that revised the code flagged it as a bug with the message "you are not returning the promise here. Either await or promise but not both". I don't really understand what he meant with this. I'm just a beginner developer and he has quite a lot more experience than me, so I assume he's right and this piece of code is wrong, but I just can't figure out why.
async componentDidMount() {
const start = Date.now();
// TODO: BUG! you are not returning the promise here! Either await or promise but not both!
const promises = [this.fetchReports({}), this.fetchEntities(), this.fetchCodePulseRange()];
await Promise.all(promises);
console.log("Data fetching time: ", Date.now() - start)
this.setState({ inited: true });
}
async fetchEntities() {
const res = await insightService.fetchEntities(this.props.profile.organisationId);
this.setState({ allEntities: res, entityType: 'product' });
}
async fetchReports(entities: { [key: string]: string }) {
const res = await insightService.fetchInsights(reports, entities, this.props.profile.organisationId, JSON.stringify(entities));
this.setState({ reportsWithData: res });
}
async fetchCodePulseRange() {
const res = await insightService.fetchCodePulseRange(this.props.profile.organisationId);
this.setState({ codePulseRange: res });
}