From 731e7dad9c13f888e73524cf8e8649176238af64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CYiliagit=20config=20--global=20user=2Eemailgit=20?= =?UTF-8?q?config=20--global=20user=2Ename=20=E2=80=9CYilia?= Date: Tue, 29 Sep 2020 19:45:42 +0800 Subject: [PATCH 1/6] docs(cn): translate react-v-16.13.0 into Chinese --- content/blog/2020-02-26-react-v16.13.0.md | 140 +++++++++++----------- 1 file changed, 72 insertions(+), 68 deletions(-) diff --git a/content/blog/2020-02-26-react-v16.13.0.md b/content/blog/2020-02-26-react-v16.13.0.md index 4fb5340426..b2ea13aa3d 100644 --- a/content/blog/2020-02-26-react-v16.13.0.md +++ b/content/blog/2020-02-26-react-v16.13.0.md @@ -5,25 +5,27 @@ redirect_from: - "blog/2020/03/02/react-v16.13.0.html" --- -Today we are releasing React 16.13.0. It contains bugfixes and new deprecation warnings to help prepare for a future major release. +我们今天发布了 React 16.13.0。它包含了 bug 修复和新的不推荐警告,来帮助准备未来的主要版本。 -## New Warnings {#new-warnings} +## 新的警告 {#new-warnings} -### Warnings for some updates during render {#warnings-for-some-updates-during-render} +### Render 期间更新的警告 {#warnings-for-some-updates-during-render} -A React component should not cause side effects in other components during rendering. +一个 React component 不应该在 render 期间对其他component造成副作用影响。 + +在 render 期间调用 `setState` 是被支持的,但是 [仅仅适用于 *同一个 component*](/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops). 如果你在另一个 component render 期间调用 `setState` ,现在你将会看到一条警告: -It is supported to call `setState` during render, but [only for *the same component*](/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops). If you call `setState` during a render on a different component, you will now see a warning: ``` Warning: Cannot update a component from inside the function body of a different component. ``` -**This warning will help you find application bugs caused by unintentional state changes.** In the rare case that you intentionally want to change the state of another component as a result of rendering, you can wrap the `setState` call into `useEffect`. +**这些警告将会帮助你找到应用中由意外的状态改变引起的 bug。** 在极少数情况下,由于渲染,你有意要更改另一个组件的状态,您可以将 `setState` 调用包装为 `useEffect`。 + -### Warnings for conflicting style rules {#warnings-for-conflicting-style-rules} +### 冲突的样式规则警告 {#warnings-for-conflicting-style-rules} -When dynamically applying a `style` that contains longhand and shorthand versions of CSS properties, particular combinations of updates can cause inconsistent styling. For example: +当动态地应用包含了全写和简写的 `style` 版本的 CSS 属性时,特定的更新组合可能会导致样式不一致。例如: ```js
``` -You might expect this `
` to always have a red background, no matter the value of `toggle`. However, on alternating the value of `toggle` between `true` and `false`, the background color start as `red`, then alternates between `transparent` and `blue`, [as you can see in this demo](https://codesandbox.io/s/suspicious-sunset-g3jub). +你可能期待这个 `
` 总是拥有红色背景,不论 `toggle` 的值是什么。然而,在 `true` 和 `false`之间交替使用`toggle`时,背景色开始是 `red`,然后在 `transparent` 和 `blue`之间交替, [像你能在这个 demo 中看到的](https://codesandbox.io/s/suspicious-sunset-g3jub). **React now detects conflicting style rules and logs a warning.** To fix the issue, don't mix shorthand and longhand versions of the same CSS property in the `style` prop. -### Warnings for some deprecated string refs {#warnings-for-some-deprecated-string-refs} +**React 现在检测到冲突的样式规则并记录警告。**要解决此问题,请不要在 `style` 属性中混合使用同一CSS属性的简写和全写版本。 + +### 某些不推荐使用的字符串 ref 的警告 {#warnings-for-some-deprecated-string-refs} -[String Refs is an old legacy API](/docs/refs-and-the-dom.html#legacy-api-string-refs) which is discouraged and is going to be deprecated in the future: +[字符串 ref 是旧版的 API](/docs/refs-and-the-dom.html#legacy-api-string-refs) 这是不可取的,将来将被弃用: ```js