@@ -5,15 +5,15 @@ redirect_from:
5
5
- " blog/2020/03/02/react-v16.13.0.html"
6
6
---
7
7
8
- 我们今天发布了 React 16.13.0。它包含了 bug 修复和新的弃用警告,来帮助准备未来的主要版本 。
8
+ 今天我们发布了 React 16.13.0。此版本修复了部分 bug 并添加了新的弃用警告,以助力接下来的主要版本 。
9
9
10
10
## 新的警告 {#new-warnings}
11
11
12
12
### Render 期间更新的警告 {#warnings-for-some-updates-during-render}
13
13
14
- 一个 React 组件不应该在 render 期间对其他组件造成副作用影响 。
14
+ React 组件不应在 render 期间对其他组件产生副作用 。
15
15
16
- 在 render 期间调用 ` setState ` 是被支持的,但是 [ 仅仅适用于* 同一个 component * ] ( /docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops ) 。 如果你在另一个 component render 期间调用 ` setState ` ,现在你将会看到一条警告。
16
+ 在 render 期间调用 ` setState ` 是被支持的,但是 [ 仅仅适用于* 同一个组件 * ] ( /docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops ) 。 如果你在另一个组件 render 期间调用 ` setState ` ,现在你将会看到一条警告。
17
17
18
18
```
19
19
Warning: Cannot update a component from inside the function body of a different component.
@@ -34,13 +34,13 @@ Warning: Cannot update a component from inside the function body of a different
34
34
< / div>
35
35
```
36
36
37
- 你可能期待这个 ` <div> ` 总是拥有红色背景,不论 ` toggle ` 的值是什么。然而,在 ` true ` 和 ` false ` 之间交替使用` toggle ` 时,背景色开始是 ` red ` ,然后在 ` transparent ` 和 ` blue ` 之间交替, [ 像你能在这个 demo 中看到的] ( https://codesandbox.io/s/suspicious-sunset-g3jub ) 。
37
+ 你可能期待这个 ` <div> ` 总是拥有红色背景,不论 ` toggle ` 的值是什么。然而,在 ` true ` 和 ` false ` 之间交替使用` toggle ` 时,背景色开始是 ` red ` ,然后在 ` transparent ` 和 ` blue ` 之间交替, [ 正如你能在这个 demo 中看到的] ( https://codesandbox.io/s/suspicious-sunset-g3jub ) 。
38
38
39
- ** React 现在检测到冲突的样式规则并记录警告 。** 要解决此问题,请不要在 ` style ` 属性中混合使用同一CSS属性的简写和全写版本。
39
+ ** React 现在检测到冲突的样式规则并打印出警告 。** 要解决此问题,请不要在 ` style ` 属性中混合使用同一CSS属性的简写和全写版本。
40
40
41
- ### 某些不推荐使用的字符串 ref 的警告 {#warnings-for-some-deprecated-string-refs}
41
+ ### 某些废弃字符串 ref 的警告 {#warnings-for-some-deprecated-string-refs}
42
42
43
- [ 字符串 ref 是旧版的 API] ( /docs/refs-and-the-dom.html#legacy-api-string-refs ) 这是不可取的,将来将被弃用:
43
+ [ 字符串 ref 是过时的 API] ( /docs/refs-and-the-dom.html#legacy-api-string-refs ) 这是不可取的,将来将被弃用:
44
44
45
45
``` js
46
46
< Button ref= " myRef" / >
@@ -73,9 +73,9 @@ class ClassParent extends React.Component {
73
73
}
74
74
```
75
75
76
- 这样的代码通常暗含 bug。(你可能希望ref在 ` ClassParent ` 上可用,但是它被放在 ` ClassWithRenderProp ` 上)。
76
+ 这样的代码通常暗含 bug。(你可能希望 ref 在 ` ClassParent ` 上可用,但是它被放在 ` ClassWithRenderProp ` 上)。
77
77
78
- ** 你很可能没有这样的代码** 。如果是故意的 ,请将其转换为[ ` React.createRef() ` ] ( /docs/refs-and-the-dom.html#creating-refs ) :
78
+ ** 你很可能没有这样的代码** 。如果是有意为之 ,请将其转换为 [ ` React.createRef() ` ] ( /docs/refs-and-the-dom.html#creating-refs ) :
79
79
80
80
``` jsx
81
81
class ClassWithRenderProp extends React .Component {
@@ -101,15 +101,15 @@ class ClassParent extends React.Component {
101
101
102
102
> Note
103
103
>
104
- > 要查看此警告,你需要在你的 Babel plugins 中安装[ babel-plugin-transform-react-jsx-self] ( https://babeljs.io/docs/en/babel-plugin-transform-react-jsx-self ) 。它必须 _ 仅仅_ 在开发模式下启用。
104
+ > 要查看此警告,你需要在你的 Babel plugins 中安装 [ babel-plugin-transform-react-jsx-self] ( https://babeljs.io/docs/en/babel-plugin-transform-react-jsx-self ) 。它必须 _ 仅仅_ 在开发模式下启用。
105
105
>
106
- > 如果你使用 Create React App 或者用 babel 7 + 预置了 React,那么默认情况下已经安装了这个插件。
106
+ > 如果你使用 Create React App 或者用 babel 7+ 的 React preset ,那么默认情况下已经安装了这个插件。
107
107
108
108
### 弃用 ` React.createFactory ` {#deprecating-reactcreatefactory}
109
109
110
110
[ ` React.createFactory ` ] ( /docs/react-api.html#createfactory ) 为 React 创建一个帮助器元素。此版本向该方法添加了一个弃用警告。它将在未来的主要版本中删除。
111
111
112
- 替换的用法 ` React.createFactory ` 用普通的 JSX 。或者可以复制并粘贴此单行辅助对象或将其发布为库:
112
+ 把 ` React.createFactory ` 替换为普通的 JSX 。或者可以复制并粘贴此单行辅助对象或将其发布为库:
113
113
114
114
``` jsx
115
115
let createFactory = type => React .createElement .bind (null , type);
@@ -125,15 +125,15 @@ let createFactory = type => React.createElement.bind(null, type);
125
125
126
126
## 其他改进 {#other-improvements}
127
127
128
- ### Hydration 过程中 Component 堆栈的警告 {#component-stacks-in-hydration-warnings}
128
+ ### Hydration 过程中组件堆栈的警告 {#component-stacks-in-hydration-warnings}
129
129
130
- React 将 Component 堆栈添加到其开发警告中 ,使开发人员能够隔离 bug 并调试他们的程序。此版本将 Component 堆栈添加到许多以前没有的开发警告中 。举个例子,考虑一下以前版本中的 hydration 警告:
130
+ React 将组件堆栈添加到其开发警告中 ,使开发人员能够隔离 bug 并调试他们的程序。此版本将组件堆栈添加到许多以前没有的开发警告中 。举个例子,考虑一下以前版本中的 hydration 警告:
131
131
132
132
![ 控制台警告的屏幕截图,简单地说明 hydration 不匹配的性质:"Warning: Expected server HTML to contain a matching div in div."] ( ../images/blog/react-v16.13.0/hydration-warning-before.png )
133
133
134
- 虽然它指出了代码中的一个错误,但不清楚错误在哪里存在,以及下一步该怎么做。此版本向此警告添加了一个 Component 堆栈 ,使其看起来如下所示:
134
+ 虽然它指出了代码中的一个错误,但不清楚错误在哪里存在,以及下一步该怎么做。此版本向此警告添加了一个组件堆栈 ,使其看起来如下所示:
135
135
136
- ![ 控制台警告的屏幕截图,说明 hydration 不匹配的性质,但也包括 Component 堆栈 :"Warning: Expected server HTML to contain a matching div in div, in div (at pages/index.js:4)..."] ( ../images/blog/react-v16.13.0/hydration-warning-after.png )
136
+ ![ 控制台警告的屏幕截图,说明 hydration 不匹配的性质,但也包括组件堆栈 :"Warning: Expected server HTML to contain a matching div in div, in div (at pages/index.js:4)..."] ( ../images/blog/react-v16.13.0/hydration-warning-after.png )
137
137
138
138
这样可以清楚地看出问题所在,并让你更快地找到并修复错误。
139
139
@@ -143,7 +143,7 @@ React 将 Component 堆栈添加到其开发警告中,使开发人员能够隔
143
143
144
144
- 在严格的开发模式下,React 调用生命周期方法两次,以清除任何可能不需要的副作用。此版本将此行为添加到 ` shouldComponentUpdate ` 中。这不会影响大多数代码,除非在 ` shouldComponentUpdate ` 中有副作用。要解决此问题,请将具有副作用的代码移到 ` componentDidUpdate ` 中。
145
145
146
- - 在严格开发模式下,使用遗留上下文 API 的警告不包括触发警告的 Component 堆栈 。此版本将丢失的堆栈添加到警告中。
146
+ - 在严格开发模式下,使用遗留上下文 API 的警告不包括触发警告的组件堆栈 。此版本将丢失的堆栈添加到警告中。
147
147
148
148
- ` onMouseEnter ` 现在在被禁用的 ` <button> ` 对象上不能被触发。
149
149
0 commit comments