reactjs / reactjs/react.dev

Missing documentation of `dispatch` function's stability

Aperta
#6,178 2 commenti 0 reazioni 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

First, I like the new React docs a lot! Unfortunately, I can no longer find the following information about useReducer that was once available in the docs:

The useReducer hook returns an array with two elements: the current state and a dispatch function. The dispatch function is used to update the state by calling it with an action object. The dispatch function returned by useReducer has a lifecycle similar to that of the component it is used in. It is created when the component mounts and destroyed when the component unmounts. The dispatch function is guaranteed to be stable across re-renders.

Is this no longer the case?

On page Lifecycle of Reactive Effects there is a note box saying "In some cases, React knows that a value never changes..." and mentioning useState and useRef. It would be ideal if the documentation would explicitly enumerate all the stable return values from hooks, i.e., the ones that share the lifecycle of their component.

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 dalla pagina «Lifecycle of Reactive Effects» e dalla documentazione attuale di useReducer, quindi confrontale con i dettagli sulla stabilità citati nell’issue. Traccia dove sono documentate le garanzie sui valori restituiti dagli hook e aggiorna la documentazione pertinente in modo che la stabilità di dispatch e i valori degli hook che dovrebbero essere stabili siano espliciti e coerenti.

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
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.