[Suggestion]: render function should be idempotent, not strictly pure
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ả
Summary
React docs explain in many instances that render should be pure and you should not read or update refs for this reason, because some features like Suspense can interrupt rendering and restart it.
But from my understanding render can be impure, what matters is that render must be idempotent, meaning interrupting render and calling it again with the same props will always return the same result. The exception given in the docs (using a ref for initialization) works because it is idempotent.
There are many other idempotent but not pure use cases, for example the implementation of what was called useEvent makes use of refs during render but should be fine.
Page
https://react.dev/reference/react/useRef#referencing-a-value-with-a-ref
Details
Change wording of pure to idempotent.
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 từ trang tham chiếu React useRef được liên kết và xem lại các phần giải thích về tính thuần khiết của quá trình render cũng như việc khởi tạo ref. Thay đổi cách diễn đạt liên quan từ “pure” thành “idempotent”, sau đó xác minh rằng trang mô tả chính xác yêu cầu đối với các lần render bị gián đoạn và lặp lại.
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ó
- 1/5
- Thời gian dự kiến
- Dưới một 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