jsx-eslint/eslint-plugin-react

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

Open

#1.110 geöffnet am 10. März 2017

Auf GitHub ansehen
 (16 Kommentare) (21 Reaktionen) (0 zugewiesene Personen)JavaScript (2.797 Forks)batch import
bughelp wanted

Repository-Metriken

Stars
 (8.630 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

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!'});
    }
  }

Contributor Guide