reactjs / reactjs/react.dev

[Suggestion]: Providing formal definition of equality of two JSX values or giving a clarity if there is no formal definition possible.

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

Chưa có ai nhận issue này.

type: documentation
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

Formal Definition of Equality of two JSX values. If there is no formal definition possible then give practical guidelines.

Page

https://react.dev/learn/keeping-components-pure

Details

React documentation on "Keeping Components Pure" says that

React assumes that every component you write is a pure function. This means that React components you write must always return the same JSX given the same inputs.

It also mentions:

React offers a “Strict Mode” in which it calls each component’s function twice during development. By calling the component functions twice, Strict Mode helps find components that break these rules.

However, the page does not provide a formal definition of what it means for two JSX values to be "equal."

we can easily say 4 === 4 or "foo" === "foo",
But, To give a simple example, how do we define the equality of two JSX values like: "<Child {childConfig}="object1"> and <Child {childConfig}="object2">"

If object1 and object2 are deeply equal, does that imply that both JSX elements are considered equal as well? Or is equality based on referential identity of object1 and object2?
I think, This distinction is important to understand what it truly means of two JSX values being same.

If such a definition exists elsewhere in the React documentation, it would be helpful to reference it explicitly from this page to clarify expectations around JSX equality and purity.

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

Bắt đầu với trang “Keeping Components Pure” được liên kết trong issue và xem lại phần giải thích về các đầu vào bằng nhau và kết quả JSX. Làm rõ liệu tính bằng nhau của JSX nên được định nghĩa một cách hình thức hay được thay thế bằng hướng dẫn thực tế về danh tính đối tượng và tính bằng nhau sâu, đồng thời thêm một tham chiếu hoặc giải thích rõ ràng để người đọc biết “cùng một JSX” nghĩa là gì.

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ó
5/5
Thời gian dự kiến
Hơn một tuần
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.