Does `dispatch` function identity change when passed in context? [Re: eslint-plugin-react-hooks]
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 11.8k
- Forks
- 7.9k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 11
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the linked useReducer and Hooks FAQ documentation first, then reproduce the warning in the CodeSandbox and compare it with eslint-plugin-react-hooks behavior. Done means determining whether the docs need clarification or the plugin behavior needs a separate fix, with the relevant conclusion recorded.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- eslint, javascript, react
- Domain
- documentation, tooling
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100