Example showing need for FlatList extraData prop is misleading
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- react-native
- Lĩnh vực
- documentation
Hướng nghiên cứu
Bắt đầu với ví dụ thứ hai tại reactnative.dev/docs/flatlist#example, sau đó đọc issue 1529 và pull request 2634 được liên kết để nắm bối cảnh trước đây. So sánh hành vi của ví dụ khi có và không có extraData, đồng thời kiểm tra hướng dẫn hiện tại về FlatList trước khi thay đổi tài liệu. Công việc được xem là hoàn tất khi ví dụ và phần giải thích mô tả chính xác khi nào cần extraData.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Basically https://github.com/react/react-native-website/issues/1529 from 2019 which was closed due to inactivity.
Related: https://github.com/react/react-native-website/pull/2634 which attempted to address this but unfortunately received no attention.
Description
The second example at https://reactnative.dev/docs/flatlist#example is introduced with
By passing
extraData={selectedId}toFlatListwe make sureFlatListitself will re-render when the state changes. Without setting this prop,FlatListwould not know it needs to re-render any items because it is a PureComponent and the prop comparison will not show any changes.
But if you delete the extraData prop everything works fine. Since renderItem closes over selectedId, it is recreated whenever selectedId changes (or on every single render if the react compiler is disabled), hence FlatList receives a new prop and re-renders properly as you'd expect.
Which makes me wonder: is there ever a need for extraData? Was it once necessary (perhaps in class component days, or old react native architecture) and is no longer needed?
I'm struggling to think of a scenario in which it's needed, other than an escape hatch for syncing with something outside react, or to opt back in to reactivity after making manual memoizations.
Currently the docs suggest it's necessary to make basic reactivity work, which is confusing.
Documentation version
0.87
- Ngôn ngữ chính
- MDX
- Star
- 2.2k
- Fork
- 6.3k
- Merge trung bình
- 11 giờ 37 phút
- Pull request đã merge (30 ngày)
- 19
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.
Issue khác của react/react-native-website
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
react/react-native-website#5217 ·
-
Integration with Existing Apps: Podfile example does not use `use_react_native!`, is incomplete Đang mở👋 Good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
react/react-native-website#2958 · 2 bình luận ·
-
:ghost: Missing Docs 👋 Good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
react/react-native-website#889 · 5 bình luận · 1 reaction ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
react/react-native-website#5154 · 6 bình luận ·
-
Never gets stale
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 38/100
react/react-native-website#4265 · 2 bình luận ·
Tất cả issue của react/react-native-website
Issue tương tự
-
The correction-threshold rationale says 17 restraint cases collide; the current corpus has 16 Đang mởarea:dictation documentation P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
uttrflow/uttrflow-swift#1180 ·
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
githubnext/gh-aw-workshop#3692 ·
-
agent/guide documentation hive/hosted-available-lke648397-260827-5n31
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
-
kind/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
falcosecurity/falco-website#1601 ·
-
Improve privacy considerations Đang mởspecification
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
WICG/webmonetization#729 ·