Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(cn) translate Learn/removing effect dependencies into Chinese #1194

Closed

Conversation

earthaYan
Copy link
Contributor

@earthaYan earthaYan commented Jun 19, 2023

@Yucohny 已完成,等待校对

@github-actions
Copy link

github-actions bot commented Jun 19, 2023

Size changes

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

Three Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/404 76.66 KB (🟢 -9 B) 179.81 KB
/500 76.65 KB (🟢 -9 B) 179.8 KB
/[[...markdownPath]] 78.22 KB (🟢 -9 B) 181.38 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

// ...
}
```

[Effects "react" to reactive values.](/learn/lifecycle-of-reactive-effects#effects-react-to-reactive-values) Since `roomId` is a reactive value (it can change due to a re-render), the linter verifies that you've specified it as a dependency. If `roomId` receives a different value, React will re-synchronize your Effect. This ensures that the chat stays connected to the selected room and "reacts" to the dropdown:
[Effect 会对响应式值“做出响应”](/learn/lifecycle-of-reactive-effects#effects-react-to-reactive-values)。由于 roomId 是响应式值(它会因为重新渲染而变化),代码检查工具会验证你是否已经将它指定为依赖项。每当 roomId 接收到一个不同的值,React 就会重新同步对应的 Effect。这可以保证聊天会一直和选中的房间保持连接,并对下拉框的变化“做出响应”:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[Effect 会对响应式值“做出响应”](/learn/lifecycle-of-reactive-effects#effects-react-to-reactive-values)。由于 roomId 是响应式值(它会因为重新渲染而变化),代码检查工具会验证你是否已经将它指定为依赖项。每当 roomId 接收到一个不同的值,React 就会重新同步对应的 Effect。这可以保证聊天会一直和选中的房间保持连接,并对下拉框的变化“做出响应”:
[Effect 会对响应式值“做出响应”](/learn/lifecycle-of-reactive-effects#effects-react-to-reactive-values)。由于 `roomId` 是响应式值(它会因为重新渲染而变化),代码检查工具会验证你是否已经将它指定为依赖项。每当 `roomId` 接收到一个不同的值,React 就会重新同步对应的 Effect。这可以保证聊天会一直和选中的房间保持连接,并对下拉框的变化“做出响应”:

@@ -263,43 +263,43 @@ button { margin-left: 10px; }

</Sandpack>

This is why you could now specify an [empty (`[]`) dependency list.](/learn/lifecycle-of-reactive-effects#what-an-effect-with-empty-dependencies-means) Your Effect *really doesn't* depend on any reactive value anymore, so it *really doesn't* need to re-run when any of the component's props or state change.
这就是为什么你现在可以指定一个 [空 (`[]`) 依赖项列表](/learn/lifecycle-of-reactive-effects#what-an-effect-with-empty-dependencies-means)Effect **实际上不再**依赖任何响应式值,所以当组件的任何 props state 变化时,它**并不**需要重新运行。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
这就是为什么你现在可以指定一个 [空 (`[]`) 依赖项列表](/learn/lifecycle-of-reactive-effects#what-an-effect-with-empty-dependencies-means)。Effect **实际上不再**依赖任何响应式值,所以当组件的任何 props 和 state 变化时,它**并不**需要重新运行。
这就是为什么你现在可以指定一个 [空 (`[]`) 依赖项列表](/learn/lifecycle-of-reactive-effects#what-an-effect-with-empty-dependencies-means)。Effect **实际上不再** 依赖任何响应式值,所以当组件的任何 props 和 state 变化时,它 **并不** 需要重新运行。


There's always a better solution than ignoring the linter! To fix this code, you need to add `onTick` to the dependency list. (To ensure the interval is only setup once, [make `onTick` an Effect Event.](/learn/separating-events-from-effects#reading-latest-props-and-state-with-effect-events))
比起忽略代码检查,有一个更好的解决方法!你需要向依赖项列表中加入 `onTick` 来修复这段代码。(为了确保 interval 只设置一次,需要 [让 `onTick` 成为 Effect Event](/learn/separating-events-from-effects#reading-latest-props-and-state-with-effect-events)。)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

考虑一下此处的 Event 是否需要翻译

@@ -435,13 +435,13 @@ function Form() {
}
```

Now that the code is in an event handler, it's not reactive--so it will only run when the user submits the form. Read more about [choosing between event handlers and Effects](/learn/separating-events-from-effects#reactive-values-and-reactive-logic) and [how to delete unnecessary Effects.](/learn/you-might-not-need-an-effect)
既然代码是在一个事件处理函数里,所以它不是响应式的 — 所以它只会在用户提交表单的时候运行。了解更多关于 [如何选择事件处理函数和 Effect](/learn/separating-events-from-effects#reactive-values-and-reactive-logic) 以及 [如何删除不必要的Effect](/learn/you-might-not-need-an-effect)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
既然代码是在一个事件处理函数里,所以它不是响应式的所以它只会在用户提交表单的时候运行。了解更多关于 [如何选择事件处理函数和 Effect](/learn/separating-events-from-effects#reactive-values-and-reactive-logic) 以及 [如何删除不必要的Effect](/learn/you-might-not-need-an-effect)
既然代码是在一个事件处理函数里,所以它不是响应式的——所以它只会在用户提交表单的时候运行。了解更多关于 [如何选择事件处理函数和 Effect](/learn/separating-events-from-effects#reactive-values-and-reactive-logic) 以及 [如何删除不必要的Effect](/learn/you-might-not-need-an-effect)


The final code is longer than the original, but splitting these Effects is still correct. [Each Effect should represent an independent synchronization process.](/learn/lifecycle-of-reactive-effects#each-effect-represents-a-separate-synchronization-process) In this example, deleting one Effect doesn't break the other Effect's logic. This means they *synchronize different things,* and it's good to split them up. If you're concerned about duplication, you can improve this code by [extracting repetitive logic into a custom Hook.](/learn/reusing-logic-with-custom-hooks#when-to-use-custom-hooks)
最终代码比原本的代码更长,但是分割这些 Effect 的做法仍然是非常正确的。[每个 Effect 应该表示一个独立的同步进程](/learn/lifecycle-of-reactive-effects#each-effect-represents-a-separate-synchronization-process)。在这个例子中,删除一个 Effect 不会破坏其他 Effect 的逻辑。这意味着他们 **同步不同的事物**,并且拆分它们是有好处的。如果你担心重复,可以通过 [提取重复逻辑到自定义 Hook ](/learn/reusing-logic-with-custom-hooks#when-to-use-custom-hooks)来改进这段代码。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
最终代码比原本的代码更长,但是分割这些 Effect 的做法仍然是非常正确的。[每个 Effect 应该表示一个独立的同步进程](/learn/lifecycle-of-reactive-effects#each-effect-represents-a-separate-synchronization-process)。在这个例子中,删除一个 Effect 不会破坏其他 Effect 的逻辑。这意味着他们 **同步不同的事物**,并且拆分它们是有好处的。如果你担心重复,可以通过 [提取重复逻辑到自定义 Hook ](/learn/reusing-logic-with-custom-hooks#when-to-use-custom-hooks)来改进这段代码。
最终代码比原本的代码更长,但是分割这些 Effect 的做法仍然是非常正确的。[每个 Effect 应该表示一个独立的同步进程](/learn/lifecycle-of-reactive-effects#each-effect-represents-a-separate-synchronization-process)。在这个例子中,删除一个 Effect 不会破坏其他 Effect 的逻辑。这意味着他们 **同步不同的事物**,并且拆分它们是有好处的。如果你担心重复,可以通过 [提取重复逻辑到自定义 Hook](/learn/reusing-logic-with-custom-hooks#when-to-use-custom-hooks) 来改进这段代码。

@Yucohny
Copy link
Collaborator

Yucohny commented Jun 19, 2023

有一些格式上的小问题,烦请自查一遍~

@Yucohny
Copy link
Collaborator

Yucohny commented Jun 19, 2023

另外,此篇翻译与此 PR 对应翻译重复。

@Yucohny Yucohny added Pending Modify 已校对,待修改阶段 repetitive discussion Need discussion labels Jun 19, 2023
@Yucohny
Copy link
Collaborator

Yucohny commented Jun 21, 2023

当出现重复翻译时,我的想法是:
(1)如果之前的翻译 PR 未在 Claims 中声明,并且你是第一个在 Claims 中声明此篇文档翻译任务领取的人,将会考虑保留你的 PR,并删除之前其他人的 PR;
(2)如果之前的翻译 PR 本身已在 Claims 中声明,建议关闭此 PR,并对照自己翻译的内容去给已经翻译的那一篇 PR 提 review。

@Yucohny Yucohny removed repetitive discussion Need discussion labels Jun 21, 2023
@earthaYan
Copy link
Contributor Author

当出现重复翻译时,我的想法是: (1)如果之前的翻译 PR 未在 Claims 中声明,并且你是第一个在 Claims 中声明此篇文档翻译任务领取的人,将会考虑保留你的 PR,并删除之前其他人的 PR; (2)如果之前的翻译 PR 本身已在 Claims 中声明,建议关闭此 PR,并对照自己翻译的内容去给已经翻译的那一篇 PR 提 review。

好的,我会关闭这个PR,并根据此翻译内容review另外一个PR

@earthaYan earthaYan closed this Jun 26, 2023
@earthaYan earthaYan deleted the learn/removing-effect-dependencies branch June 26, 2023 06:33
@earthaYan earthaYan restored the learn/removing-effect-dependencies branch June 26, 2023 07:07
@earthaYan earthaYan deleted the learn/removing-effect-dependencies branch June 28, 2023 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pending Modify 已校对,待修改阶段
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants