Does `dispatch` function identity change when passed in context? [Re: eslint-plugin-react-hooks]
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 11.8k
- Fork
- 7.9k
- Merge medio
- 1g 11h
- PR unite (30g)
- 11
Descrizione
Issue:
-
The docs for useReducer suggests omitting
dispatchfrom the dependencies list ofuseEffectanduseReducer.Note
React guarantees thatdispatchfunction identity is stable and won't change on re-renders. This is why it's safe to omit from theuseEffectoruseCallbackdependency list. -
The docs also recommend passing
dispatchfunction fromuseReducervia context to avoid passing callbacks down a large component tree: -
eslint-plugin-react-hooks warns if
dispatch(that's been passed from context) is not added touseEffectdependencies list.This conflicts with the first point above (docs suggesting omitting
dispatchfrom the dependencies list)React Hook useCallback has a missing dependency: 'dispatch'. Either include it or remove the dependency array.
Is this:
- Expected behavior after passing
dispatchthrough context - so the docs should have a small amendment for this scenario? - Or a bug in
eslint-plugin-react-hooks?
Thanks for the help!!
Working Sample:
- Example Sandbox: https://codesandbox.io/s/vnq10rmwjy
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
Leggi prima la documentazione collegata su useReducer e le FAQ di Hooks, quindi riproduci l’avviso in CodeSandbox e confrontalo con il comportamento di eslint-plugin-react-hooks. Il lavoro è completato quando è stato determinato se la documentazione necessita di un chiarimento o se il comportamento del plugin richiede una correzione separata, e la relativa conclusione è stata annotata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- eslint, javascript, react
- Ambito
- documentation, tooling
- Tipo di issue
- Documentazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100