[Documentation] Add information about `child.key` to `React.Children.map`
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ả
I just spent quite a while debugging a performance issue when reordering a large list of components, which were wrapped in React.Children.map.
The issue was the implementation of the wrapping component, which used the index as the key, which caused the entire list to re-render from scratch:
<div>
{React.Children.map(props.children, (child, index) => (
<div key={index} className='...'>{child}</div>
))}
</div>
The solution was to use child.key and pass it into the child-component, which then, in turn, made the memoization of the child components work as expected:
<div>
{React.Children.map(props.children, (child) => (
<div key={child.key} className='...'>{child}</div>
))}
</div>
I feel like this should be mentioned somewhere on the documentation page for React.Children.map, since I only figured out that this is possible at all after specifically searching for it and finding #10432.
I'm happy to update the docs in a PR if this gets the OK :)
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
Bắt đầu với phần React.Children.map trên trang tài liệu React API được liên kết trong issue và xem lại cuộc thảo luận liên quan trong issue #10432. Bổ sung thông tin rõ ràng về child.key và tầm quan trọng của nó khi bọc children, sau đó xác minh rằng tài liệu giải thích cách sử dụng dự kiến và yếu tố cần cân nhắc về hiệu năng.
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ó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 55/100