reactjs / reactjs/react.dev

[Typo]: Two docs give conflict answers about when effects will run

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

@poteto 已经在做这个了。

开始于 2025年5月16日。

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

描述

Summary

https://react.dev/learn/synchronizing-with-effects#how-to-write-an-effect
This link says React effects run after the commit phase, but

https://react.dev/reference/rules/components-and-hooks-must-be-pure#how-does-react-run-your-code
this link says it's after the rendering phase

Page

https://react.dev/learn/synchronizing-with-effects#how-to-write-an-effect

Details

In https://react.dev/learn/synchronizing-with-effects#how-to-write-an-effect, it says:

Declare an Effect. By default, your Effect will run after every commit.

(it also says:

Specify the Effect dependencies. Most Effects should only re-run when needed rather than after every render.)

But in https://react.dev/reference/rules/components-and-hooks-must-be-pure#how-does-react-run-your-code, it says:

After rendering, Effects are flushed (meaning they are run until there are no more left) and may update the calculation if the Effects have impacts on layout. React takes this new calculation and compares it to the calculation used to create the previous version of your UI, then commits just the minimum changes needed to the DOM (what your user actually sees) to catch it up to the latest version.

I think their explanation about when effects will run conflicts with each other. Looks like the former one says effects run after commit, but the latter two says effects run after render, and when these effects finish taking affects, React then enters the commit phase.

This is a bit confusing for me. Maybe one of them gives wrong explanation?

贡献指南

打开贡献指南

从这里开始

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

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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