1

If lifecycle methods on React components are marked async, are they treated differently?

    default class MyComponent extends Component {
      state = {};

      async componentDidMount() {
        await this.fillQuestions();
      }
    }
Ben Aston
  • 53,718
  • 65
  • 205
  • 331

1 Answers1

2

There's no difference between the way they're being called. async only means that the function will return Promise. and since React doesn't expect any return value, there's no difference between the two from React's point of view.

However, you can use async when you want to await for some other promise inside your lifecycle hook.

Take a look at the following medium article: https://medium.com/front-end-weekly/async-await-with-react-lifecycle-methods-802e7760d802

evolon
  • 1,276
  • 1
  • 10
  • 18