-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
Deploy preview for cn-reactjs ready! Built with commit 32b1947 |
Deploy preview for zh-hans-reactjs ready! Built with commit 32b1947 |
|
||
> Note | ||
> 译注 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,@maicss 译注使用上角标的形式,放在文章末尾,否则会对合并和 review 带来很大的困难哟~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
保证原文行行统一🤝
好的👌
发自iPhone 18
… 在 2019年3月16日,23:20,QiChang Li ***@***.***> 写道:
@QC-L commented on this pull request.
In content/blog/2018-06-07-you-probably-dont-need-derived-state.md:
>
-> Note
+> 译注
***@***.*** 译注使用上角标的形式,放在文章末尾,否则会对合并和 review 带来很大的困难哟~
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
标题改一下哈 |
中英文之间的空格问题,一会按照规范修改,谢谢。 |
有什么建议的标题吗? |
@maicss 标题只改内容,不用改符号 |
比如呢...我没get到你们的点,比如 |
@@ -1,46 +1,46 @@ | |||
--- | |||
title: "You Probably Don't Need Derived State" | |||
title: “你可能不需要使用Derived State” |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
title: “你可能不需要使用Derived State” | |
title: "你可能不需要使用 Derived State" |
There was a problem hiding this comment.
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, 如果决定了叫这个,那我里面的就全部修改掉
前两个是疑问。我对文档的翻译不是很熟练,如果这个词你们确定了这样翻译,那我就做第三步。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不不不,我刚刚没仔细看
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不是让你改标题,是注意符号问题
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,我再修改一下
@maicss React 中文文档译文规范,这是大纲,具体详细,一会完善并给出示例。 |
@@ -1,46 +1,46 @@ | |||
--- | |||
title: "You Probably Don't Need Derived State" | |||
title: “你可能不需要使用 Derived State ” |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处术语 md 的一部分,语法上使用英文的引号
title: “你可能不需要使用 Derived State ” | |
title: "你可能不需要使用 Derived State" |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这句话感觉删掉吧,“好像不怎么”,“我觉得”这种词语放在文档里不合适。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删掉后,不翻译可以吗?
There was a problem hiding this comment.
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 行为。这是正常的!不过如果每个值都有明确的来源,就可以避免上面提到的反面模式。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“受控”和“非受控”有专门的翻译
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个我考虑过了,因为原文后面跟了一个behaviors,直接翻译成受控可以吗,这是咨询,不是讨论
There was a problem hiding this comment.
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: “你可能不需要使用派生状态” |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是 md 语法的一部分,使用英文引号
title: “你可能不需要使用派生状态” | |
title: "你可能不需要使用派生 State" |
content/blog/2018-06-07-you-probably-dont-need-derived-state.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 。如果这个版本导致出现的问题,导致您在修复过之后还已知出现的话,我们非常抱歉。在这篇文章里,我们会展示一些常见的反面模式,和相对应的,我们推荐的模式。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
后面已经是全角的标点了,就不需要空格了。
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 更容易被发现。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在很长一段时间内,生命周期函数 `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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* [什么时候使用派生 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* [反面模式:在 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* [尝试一下 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)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`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)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 如果你只是为了缓存( memoize )基于当前 props 计算后的结果的话,你就没必要使用派生 state 。[尝试一下 memoization ?](#what-about-memoization)。 | |
* 如果你只是为了缓存(memoize)基于当前 props 计算后的结果的话,你就没必要使用派生 state。[尝试一下 memoization?](#what-about-memoization)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM,改下笔误就行
No description provided.