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..66bc079577 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,25 @@ 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 组件不应在 render 期间对其他组件产生副作用。 -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: +在 render 期间调用 `setState` 是被支持的,但是 [仅仅适用于*同一个组件*](/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops)。 如果你在另一个组件 render 期间调用 `setState`,现在你将会看到一条警告。 ``` 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. +**React 现在检测到冲突的样式规则并打印出警告。**要解决此问题,请不要在 `style` 属性中混合使用同一CSS属性的简写和全写版本。 -### Warnings for some deprecated string refs {#warnings-for-some-deprecated-string-refs} +### 某些废弃字符串 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