Make it clearer how to run an effect only once (componentDidMount style)
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 11.8k
- Fork
- 7.9k
- Merge medio
- 1g 11h
- PR unite (30g)
- 11
Descrizione
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?
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dalla documentazione dell’effect hook e dalla sezione «Suggerimento: ottimizzare le prestazioni saltando gli effetti», dove attualmente è nascosta la guida sull’esecuzione una sola volta al mount. Decidi se l’esempio useEffect-on-mount appartenga a una sezione o a un suggerimento con priorità maggiore, quindi conferma che la documentazione spieghi chiaramente il pattern previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, react
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100