Make it clearer how to run an effect only once (componentDidMount style)
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
Based on this conversation on Twitter, it's perhaps not clear enough how to make an effect hook only run once on mount (a la componentDidMount.)
The relevant info on how to do it properly is tucked away near the bottom of the effect hook doc, in a footnote of this tip. This is a major use case that should probably have higher priority in the documentation. I imagine a vast majority of apps actually need to do use an effect in this manner.
I assume people are probably doing something like
function MyComponent({ fetchData, data }) {
useEffect(() => {
if (!data) {
fetchData()
}
})
}
I can make the change to the docs, but where's the best place to put it? Should I make it a tip? Does it deserve higher priority than that?
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
Beginne mit der Dokumentation zum Effect Hook und ihrem Abschnitt „Tipp: Performance durch das Überspringen von Effects optimieren“, in dem die Anleitung für die einmalige Ausführung beim Mount derzeit versteckt ist. Entscheide, ob das useEffect-on-mount-Beispiel in einen Abschnitt oder Tipp mit höherer Priorität gehört, und bestätige anschließend, dass die Dokumentation das beabsichtigte Muster klar erklärt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, react
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100