UP | HOME

React's componentDidMount with async

It's safe to add async to componentDidMount to be able to use async/await in it.

async componentDidMount(): Promise<void> {
  await doSomething();
}

The above is the same as:

componentDidMount(): void {
  doSomething()
    .then(() => { ... });
}

Date: 2019-01-25 Fri 00:00

Author: Huy Tran

Created: 2019-04-22 Mon 14:41