Explain why componentDidMount is a better place to make an ajax request
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 11.8k
- Forks
- 7.9k
- Ø Merge
- 1 T. 11 Std.
- Gemergte PRs (30 T.)
- 11
Beschreibung
In the docs, in componentWillMount section section it says:
Avoid introducing any side-effects or subscriptions in this method
And in the componentDidMount section:
If you need to load data from a remote endpoint, this is a good place to instantiate the network request
Which for me is confusing because I won't like to wait for the component to be mounted to dispatch an ajax call to fulfill the component data dependencies. I would like to do it as soon as possible, like in the constructor, not even in componentWillMount.
Clearly you may have a reason why you say this in the docs, I might be not seeing the bigger picture. So it will be nice if you can explain a bit more in detail or point me in the direction of where I can find the reason.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Lies die verlinkten Abschnitte zu componentWillMount und componentDidMount in der React-Dokumentation sowie die umgebenden Hinweise zum Lebenszyklus. Kläre, warum die Dokumentation empfiehlt, Remote-Anfragen in componentDidMount zu starten, und gehe auf die Bedenken ein, bis zum Mounten zu warten; das Issue ist abgeschlossen, wenn die zeitlichen Vorgaben und die Begründung klar sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, react
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100