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.

未关闭
#7,751 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

type: documentation
主要语言
JavaScript
星标
11.8k
派生
7.9k
平均合并
1 天 11 小时
30 天内合并 PR
11

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 issue 中链接的“Keeping Components Pure”页面开始,查看其中对相同输入和 JSX 结果的解释。明确 JSX 相等性是否应当进行形式化定义,还是改为提供有关对象身份和深度相等的实践性指导,并添加明确的参考或解释,让读者知道“相同的 JSX”是什么意思。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, react
领域
documentation
Issue 类型
文档
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。