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 content/blog/2018-06-07-you-probably-dont-need-derived-state.md into Chinese #168

Merged
merged 9 commits into from May 19, 2019

Conversation

maicss
Copy link
Contributor

@maicss maicss commented Mar 16, 2019

No description provided.

@netlify
Copy link

netlify bot commented Mar 16, 2019

Deploy preview for cn-reactjs ready!

Built with commit 32b1947

https://deploy-preview-168--cn-reactjs.netlify.com

@netlify
Copy link

netlify bot commented Mar 16, 2019

Deploy preview for zh-hans-reactjs ready!

Built with commit 32b1947

https://deploy-preview-168--zh-hans-reactjs.netlify.com


> Note
> 译注
Copy link
Member

Choose a reason for hiding this comment

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

Hi,@maicss 译注使用上角标的形式,放在文章末尾,否则会对合并和 review 带来很大的困难哟~

Copy link
Member

Choose a reason for hiding this comment

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

保证原文行行统一🤝

@maicss
Copy link
Contributor Author

maicss commented Mar 16, 2019 via email

1 把译注放在文章下面
2 翻译之后的行和原文的行保证一致
@yuqingc
Copy link
Member

yuqingc commented Mar 17, 2019

标题改一下哈

@QC-L
Copy link
Member

QC-L commented Mar 17, 2019

中英文之间的空格问题,一会按照规范修改,谢谢。
规范稍后提交

@maicss
Copy link
Contributor Author

maicss commented Mar 17, 2019

标题改一下哈

有什么建议的标题吗?

@QC-L
Copy link
Member

QC-L commented Mar 17, 2019

@maicss 标题只改内容,不用改符号

@maicss
Copy link
Contributor Author

maicss commented Mar 17, 2019

@maicss 标题只改内容,不用改符号

比如呢...我没get到你们的点,比如请少使用还是使用xxx的常见误区

@@ -1,46 +1,46 @@
---
title: "You Probably Don't Need Derived State"
title: “你可能不需要使用Derived State
Copy link
Member

@QC-L QC-L Mar 17, 2019

Choose a reason for hiding this comment

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

Suggested change
title: “你可能不需要使用Derived State
title: "你可能不需要使用 Derived State"

Copy link
Contributor Author

@maicss maicss Mar 17, 2019

Choose a reason for hiding this comment

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

1, JavaScript里有个关于提升的词,叫Hoisting
2, React文档里也有个lifting-state-up
3, 如果决定了叫这个,那我里面的就全部修改掉


前两个是疑问。我对文档的翻译不是很熟练,如果这个词你们确定了这样翻译,那我就做第三步。

Copy link
Member

Choose a reason for hiding this comment

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

不不不,我刚刚没仔细看

Copy link
Member

Choose a reason for hiding this comment

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

不是让你改标题,是注意符号问题

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,我再修改一下

@QC-L
Copy link
Member

QC-L commented Mar 17, 2019

@maicss React 中文文档译文规范,这是大纲,具体详细,一会完善并给出示例。

@maicss maicss changed the title 翻译完成 docs(cn): translate content/blog/2018-06-07-you-probably-dont-need-derived-state.md into Chinese Mar 17, 2019
@QC-L QC-L added Pending Review 已翻译,待校对阶段 and removed Pending Review 已翻译,待校对阶段 labels Mar 18, 2019
@@ -1,46 +1,46 @@
---
title: "You Probably Don't Need Derived State"
title: “你可能不需要使用 Derived State
Copy link
Member

Choose a reason for hiding this comment

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

此处术语 md 的一部分,语法上使用英文的引号

Suggested change
title: 你可能不需要使用 Derived State
title: "你可能不需要使用 Derived State"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的


**译注:**

<a name="note1"></a> [1] derived state 应该翻译成派生状态,但是这个词好像并不怎么流行,不是那么通用。所以我觉得就没必要再记一个新的词汇了,就没翻译。<br>
Copy link
Member

Choose a reason for hiding this comment

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

这句话感觉删掉吧,“好像不怎么”,“我觉得”这种词语放在文档里不合适。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

删掉后,不翻译可以吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

删掉后,不翻译可以吗?


In real world applications, components often contain a mix of controlled and uncontrolled behaviors. This is okay! If each value has a clear source of truth, you can avoid the anti-patterns mentioned above.
在实际应用中,组件一般都会有 controlled uncontrolled 行为。这是正常的!不过如果每个值都有明确的来源,就可以避免上面提到的反面模式。
Copy link
Member

Choose a reason for hiding this comment

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

“受控”和“非受控”有专门的翻译

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个我考虑过了,因为原文后面跟了一个behaviors,直接翻译成受控可以吗,这是咨询,不是讨论

Copy link
Member

Choose a reason for hiding this comment

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

发邮件给你了,可以在群里讨论。

@@ -1,38 +1,38 @@
---
title: “你可能不需要使用 Derived State
title: “你可能不需要使用派生状态
Copy link
Member

Choose a reason for hiding this comment

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

这里是 md 语法的一部分,使用英文引号

Suggested change
title: “你可能不需要使用派生状态”
title: "你可能不需要使用派生 State"

@yuqingc yuqingc added Pending Modify 已校对,待修改阶段 and removed Pending Review 已翻译,待校对阶段 labels Mar 23, 2019
@QC-L QC-L mentioned this pull request Mar 24, 2019
Copy link
Member

@yuqingc yuqingc left a comment

Choose a reason for hiding this comment

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

后文都有同样的问题,需要统一修改。全角标点符号和英文单词之间不需要空格

author: [bvaughn]
---

React 16.4 included a [bugfix for getDerivedStateFromProps](/blog/2018/05/23/react-v-16-4.html#bugfix-for-getderivedstatefromprops) which caused some existing bugs in React components to reproduce more consistently. If this release exposed a case where your application was using an anti-pattern and didn't work properly after the fix, we're sorry for the churn. In this post, we will explain some common anti-patterns with derived state and our preferred alternatives.
React 16.4 版本修复了一个 [getDerivedStateFromProps 的 bug ](/blog/2018/05/23/react-v-16-4.html#bugfix-for-getderivedstatefromprops),这个 bug 会在 React components 复现一些已知的 bug 。如果这个版本导致出现的问题,导致您在修复过之后还已知出现的话,我们非常抱歉。在这篇文章里,我们会展示一些常见的反面模式,和相对应的,我们推荐的模式。
Copy link
Member

Choose a reason for hiding this comment

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

后面已经是全角的标点了,就不需要空格了。

Suggested change
React 16.4 版本修复了一个 [getDerivedStateFromProps 的 bug ](/blog/2018/05/23/react-v-16-4.html#bugfix-for-getderivedstatefromprops),这个 bug 会在 React components 复现一些已知的 bug 。如果这个版本导致出现的问题,导致您在修复过之后还已知出现的话,我们非常抱歉。在这篇文章里,我们会展示一些常见的反面模式,和相对应的,我们推荐的模式。
React 16.4 版本修复了一个 [getDerivedStateFromProps 的 bug](/blog/2018/05/23/react-v-16-4.html#bugfix-for-getderivedstatefromprops),这个 bug 会在 React components 复现一些已知的 bug。如果这个版本导致出现的问题,导致您在修复过之后还已知出现的话,我们非常抱歉。在这篇文章里,我们会展示一些常见的反面模式,和相对应的,我们推荐的模式。


For a long time, the lifecycle `componentWillReceiveProps` was the only way to update state in response to a change in props without an additional render. In version 16.3, [we introduced a replacement lifecycle, `getDerivedStateFromProps`](/blog/2018/03/29/react-v-16-3.html#component-lifecycle-changes) to solve the same use cases in a safer way. At the same time, we've realized that people have many misconceptions about how to use both methods, and we've found anti-patterns that result in subtle and confusing bugs. The `getDerivedStateFromProps` bugfix in 16.4 [makes derived state more predictable](https://github.com/facebook/react/issues/12898), so the results of misusing it are easier to notice.
在很长一段时间内,生命周期函数 `componentWillReceiveProps` 是响应 Props 变化之后进行更新的唯一方式。16.3 版本里, [我们介绍了一个替代版的生命周期函数: `getDerivedStateFromProps`](/blog/2018/03/29/react-v-16-3.html#component-lifecycle-changes) ,尝试用一个更安全的方式达到同样的目的。与此同时,我们意识到人们对如何使用这两种方法存在许多误解,并且我们发现反模式会导致细微而混乱的错误。16.4 版本修复的这个 bug , [让派生 state 更加可控](https://github.com/facebook/react/issues/12898),会让滥用导致的 bug 更容易被发现。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
在很长一段时间内,生命周期函数 `componentWillReceiveProps` 是响应 Props 变化之后进行更新的唯一方式。16.3 版本里, [我们介绍了一个替代版的生命周期函数: `getDerivedStateFromProps`](/blog/2018/03/29/react-v-16-3.html#component-lifecycle-changes) ,尝试用一个更安全的方式达到同样的目的。与此同时,我们意识到人们对如何使用这两种方法存在许多误解,并且我们发现反模式会导致细微而混乱的错误。16.4 版本修复的这个 bug , [让派生 state 更加可控](https://github.com/facebook/react/issues/12898),会让滥用导致的 bug 更容易被发现。
在很长一段时间内,生命周期函数 `componentWillReceiveProps` 是响应 Props 变化之后进行更新的唯一方式。16.3 版本里, [我们介绍了一个替代版的生命周期函数:`getDerivedStateFromProps`](/blog/2018/03/29/react-v-16-3.html#component-lifecycle-changes) ,尝试用一个更安全的方式达到同样的目的。与此同时,我们意识到人们对如何使用这两种方法存在许多误解,并且我们发现反模式会导致细微而混乱的错误。16.4 版本修复的这个 bug ,[让派生 state 更加可控](https://github.com/facebook/react/issues/12898),会让滥用导致的 bug 更容易被发现。

* [Preferred solutions](#preferred-solutions)
* [What about memoization?](#what-about-memoization)
这篇blog包含以下主题:
* [什么时候使用派生 state ](#when-to-use-derived-state)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* [什么时候使用派生 state ](#when-to-use-derived-state)
* [什么时候使用派生 state](#when-to-use-derived-state)

* [什么时候使用派生 state ](#when-to-use-derived-state)
* [派生 state 的常见 bug](#common-bugs-when-using-derived-state)
* [反面模式 <sup><a href="#note1">[1]</a></sup>:直接复制 props 到 state 上](#anti-pattern-unconditionally-copying-props-to-state)
* [反面模式:在 props 变化后修改 state ](#anti-pattern-erasing-state-when-props-change)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* [反面模式:在 props 变化后修改 state ](#anti-pattern-erasing-state-when-props-change)
* [反面模式:在 props 变化后修改 state](#anti-pattern-erasing-state-when-props-change)

* [反面模式 <sup><a href="#note1">[1]</a></sup>:直接复制 props state](#anti-pattern-unconditionally-copying-props-to-state)
* [反面模式:在 props 变化后修改 state ](#anti-pattern-erasing-state-when-props-change)
* [建议的模式](#preferred-solutions)
* [尝试一下 memoization](#what-about-memoization)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* [尝试一下 memoization ](#what-about-memoization)
* [尝试一下 memoization?](#what-about-memoization)


`getDerivedStateFromProps` exists for only one purpose. It enables a component to update its internal state as the result of **changes in props**. Our previous blog post provided some examples, like [recording the current scroll direction based on a changing offset prop](/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props) or [loading external data specified by a source prop](/blog/2018/03/27/update-on-async-rendering.html#fetching-external-data-when-props-change).
`getDerivedStateFromProps` 的存在只有一个目的:让组件在 **props 变化**时更新 state 。上一个 blog 展示了一些示例,比如 [props 的 offset 变化时,修改当前的滚动方向](/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props)和[根据 props 变化加载外部数据](/blog/2018/03/27/update-on-async-rendering.html#fetching-external-data-when-props-change)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`getDerivedStateFromProps` 的存在只有一个目的:让组件在 **props 变化**时更新 state 。上一个 blog 展示了一些示例,比如 [props 的 offset 变化时,修改当前的滚动方向](/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props)[根据 props 变化加载外部数据](/blog/2018/03/27/update-on-async-rendering.html#fetching-external-data-when-props-change)
`getDerivedStateFromProps` 的存在只有一个目的:让组件在 **props 变化**时更新 state。上一个 blog 展示了一些示例,比如 [props 的 offset 变化时,修改当前的滚动方向](/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props)[根据 props 变化加载外部数据](/blog/2018/03/27/update-on-async-rendering.html#fetching-external-data-when-props-change)


* If you're using derived state to memoize some computation based only on the current props, you don't need derived state. See [What about memoization?](#what-about-memoization) below.
* If you're updating derived state unconditionally or updating it whenever props and state don't match, your component likely resets its state too frequently. Read on for more details.
* 如果你只是为了缓存( memoize )基于当前 props 计算后的结果的话,你就没必要使用派生 state 。[尝试一下 memoization ?](#what-about-memoization)。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* 如果你只是为了缓存( memoize )基于当前 props 计算后的结果的话,你就没必要使用派生 state [尝试一下 memoization ](#what-about-memoization)
* 如果你只是为了缓存(memoize)基于当前 props 计算后的结果的话,你就没必要使用派生 state。[尝试一下 memoization?](#what-about-memoization)

yuqingc
yuqingc previously approved these changes Mar 28, 2019
@LeoEatle LeoEatle added Pending Re-Review 已修改,待审校阶段 and removed Pending Modify 已校对,待修改阶段 labels Mar 29, 2019
LeoEatle
LeoEatle previously approved these changes May 16, 2019
Copy link
Collaborator

@LeoEatle LeoEatle left a comment

Choose a reason for hiding this comment

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

LGTM,改下笔误就行

@LeoEatle LeoEatle dismissed stale reviews from yuqingc and themself via 32b1947 May 16, 2019 13:59
@QC-L QC-L merged commit fa97943 into reactjs:master May 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pending Re-Review 已修改,待审校阶段
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants