Skip to content

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

Open
@krp12345

Description

@krp12345

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions