react.dev icon indicating copy to clipboard operation
react.dev copied to clipboard

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

Open krp12345 opened this issue 7 months ago • 0 comments
trafficstars

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.

krp12345 avatar Apr 19 '25 06:04 krp12345