Does `dispatch` function identity change when passed in context? [Re: eslint-plugin-react-hooks]
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 11.8k
- Fork
- 7.9k
- Merge trung bình
- 1 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 11
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Trước tiên, hãy đọc tài liệu được liên kết về useReducer và Hooks FAQ, sau đó tái hiện cảnh báo trong CodeSandbox và so sánh với hành vi của eslint-plugin-react-hooks. Công việc được xem là hoàn tất khi xác định được tài liệu cần được làm rõ hay hành vi của plugin cần một bản sửa riêng, đồng thời ghi lại kết luận liên quan.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- eslint, javascript, react
- Lĩnh vực
- documentation, tooling
- Loại issue
- Tài liệu
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100