[英]Async React component lifecycle methods
如果 React 組件上的生命周期方法被標記為async
,它們會被區別對待嗎?
default class MyComponent extends Component {
state = {};
async componentDidMount() {
await this.fillQuestions();
}
}
他們被調用的方式沒有區別。 async
僅意味着該函數將返回 Promise。 由於 React 不期望任何返回值,因此從 React 的角度來看,兩者之間沒有區別。
然而,當你想在你的生命周期鈎子中await
一些其他的承諾時,你可以使用async
。
請查看以下媒體文章: https ://medium.com/front-end-weekly/async-await-with-react-lifecycle-methods-802e7760d802
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.