reactjs / reactjs/react.dev

Amend documentation for skipping useEffect

Aperta
#1,799 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
JavaScript
Stelle
11.8k
Fork
7.9k
Merge medio
1g 11h
PR unite (30g)
11

Descrizione

This is a documentation improvement request.

Currently https://reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skipping-effects explains skipping a useEffect based on a state variable by showing the following code:

useEffect(() => {
  document.title = `You clicked ${count} times`;
}, [count]); // Only re-run the effect if count changes

With the following explanation:

In the example above, we pass [count] as the second argument. What does this mean? If the count is 5, and then our component re-renders with count still equal to 5, React will compare [5] from the previous render and [5] from the next render. Because all items in the array are the same (5 === 5), React would skip the effect. That’s our optimization.

However, as the array we're shown only has a single element it, it is ambiguous what "all the items in the array" means. E.g. we cannot tell whether that's intentional phrasing, or just "plain English" that isn't actually tied to any technical precision.

Could this phrasing either be made more explicit, or (ideally) can an extra paragraph be added to explain what happens to an array with more than one element?

(originally filed as from https://github.com/facebook/react/issues/15068)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la sezione “Tip: Optimizing Performance by Skipping Effects” di docs/hooks-effect.html, collegata nell’issue. Esamina la spiegazione dell’array delle dipendenze [count] e chiarisci come funzionano i confronti quando un array contiene più elementi. Il lavoro è completato quando la documentazione spiega esplicitamente e senza ambiguità il caso con più elementi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, react
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.