jsx-eslint/eslint-plugin-react

Should react/no-did-mount-set-state trigger on ES2017 async componentDidMount?

開放

#1,110 建立於 2017年3月10日

 (16 則留言) (21 個反應) (0 位負責人)JavaScript (2,732 個分叉)batch import
bughelp wanted

倉庫指標

星標
 (9,293 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

The rule react/no-did-mount-set-state triggers error on async componentDidMount function for a deferred setState. Basically, this.setState() is being called here after an async operation has been completed. It is not re-rendering straight after mounting, but only after some data has been retrieved from a server. Does it make sense to error on this?

async componentDidMount() {
    try {
      await someAsyncOperation();
    } catch (e) {
      this.setState({errorMessage: 'Failed to load data!'});
    }
  }

貢獻者指南