reactjs / reactjs/react.dev

Render Props and PureComponent docs question/improvement opportunity

Đang mở
#825 4 bình luận 1 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ả

https://github.com/reactjs/reactjs.org/blob/b4b68460e2377837df6e1826e77af173dc205f4f/content/docs/render-props.md

In the above link, the last section ("Caveats") talks about how one can avoid killing PureComponents benefits by pulling the render prop function out into an instance method. I understand why this is the case; the 'anonymous' function 'pointer' would change every render, so it isn't seen as something that didn't change, and the PureComponent would re-render all the time.

However, it says you can't do that with a PureComponent if the instance method / render prop needs to reference the component's state/props:

In cases where you cannot define the prop statically (e.g. because you need to close over the component's props and/or state) <Mouse> should extend React.Component instead.

I don't really understand why that is a limitation, so I'm proposing this as both a question and a suggestion for an update to the docs. I've never used or really looked into PureComponent, but from a look at the docs for them it seems like they re-render if a shallow comparison of it's props/state shows a difference. If that's the case, why wouldn't an instance function on Mouse that used it's own props/state work with PureComponent? The Mouse would re-render if one changed.

(Is it because the Cat - the child component of the render prop Mouse - wouldn't re-render, even though it's parent would?)

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

Đọc content/docs/render-props.md, đặc biệt là phần “Caveats” ở cuối và hướng dẫn về PureComponent trong đó. Làm rõ tại sao một phương thức render-prop của instance sử dụng props hoặc state lại được mô tả là không tương thích với PureComponent, bao gồm cả việc hành vi render của component con có ảnh hưởng hay không. Hoàn thành khi tài liệu trả lời trực tiếp câu hỏi này và giải thích giới hạ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ệ
javascript, react
Lĩnh vực
documentation
Loại issue
Tài liệu
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/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.