reactjs / reactjs/react.dev

Does `dispatch` function identity change when passed in context? [Re: eslint-plugin-react-hooks]

Đang mở
#1,889 13 bình luận 12 reaction 0 người được giao Xem trên GitHub

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 dispatch from the dependencies list of useEffect and useReducer.

    Note
    React guarantees that dispatch function identity is stable and won't change on re-renders. This is why it's safe to omit from the useEffect or useCallback dependency list.

  • The docs also recommend passing dispatch function from useReducer via 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 to useEffect dependencies list.

    This conflicts with the first point above (docs suggesting omitting dispatch from 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 dispatch through 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:

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. 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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.