Skip to content

Commit 56a21a3

Browse files
author
zhaozhiming
committed
fix: fix review
1 parent 76fd9de commit 56a21a3

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

content/docs/lists-and-keys.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ next: forms.html
88

99
首先,让我们看下在 Javascript 中如何转化列表。
1010

11-
如下代码,我们使用 [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) 函数让数组中的每一项变双倍,然后我们得到了一个新的列表 `doubled`
11+
如下代码,我们使用 [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) 函数让数组中的每一项变双倍,然后我们得到了一个新的列表 `doubled`并打印出来
1212

1313
```javascript{2}
1414
const numbers = [1, 2, 3, 4, 5];
@@ -24,7 +24,7 @@ console.log(doubled);
2424

2525
你可以通过使用 `{}` 在 JSX 内构建一个[元素集合](/docs/introducing-jsx.html#embedding-expressions-in-jsx)
2626

27-
下面,我们使用 Javascript 中的 [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) 方法来遍历 `numbers` 数组。将数组中的每个元素变成 `<li>` 标签,最后我们得到一个数组 `listItems`
27+
下面,我们使用 Javascript 中的 [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) 方法来遍历 `numbers` 数组。将数组中的每个元素变成 `<li>` 标签,最后我们将得到的数组赋值给 `listItems`
2828

2929
```javascript{2-4}
3030
const numbers = [1, 2, 3, 4, 5];
@@ -44,7 +44,7 @@ ReactDOM.render(
4444

4545
[在 CodePen 上尝试](https://codepen.io/gaearon/pen/GjPyQr?editors=0011)
4646

47-
这段代码生成了一个 1 到 5 的数字列表
47+
这段代码生成了一个 1 到 5 的项目符号列表
4848

4949
### 基础列表组件 {#basic-list-component}
5050

@@ -130,15 +130,15 @@ const todoItems = todos.map((todo, index) =>
130130
);
131131
```
132132

133-
如果列表项目的顺序可能会变化,我们不建议使用索引来用作键值,因为这样做会导致性能变差,还可能引起组件状态的问题。可以看看 Robin Pokorny 的[深度解析使用索引作为 key 的副作用](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318) 这一篇文章。如果你选择不指定显式的键值,那么 React 将默认使用索引用作为列表项目的键值。
133+
如果列表项目的顺序可能会变化,我们不建议使用索引来用作键值,因为这样做会导致性能变差,还可能引起组件状态的问题。可以看看 Robin Pokorny 的[深度解析使用索引作为 key 的负面影响](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318) 这一篇文章。如果你选择不指定显式的键值,那么 React 将默认使用索引用作为列表项目的键值。
134134

135-
要是你有兴趣了解更多的话,这里有一篇文章 [in-depth explanation about why keys are necessary](/docs/reconciliation.html#recursing-on-children) 可以参考。
135+
要是你有兴趣了解更多的话,这里有一篇文章 [深入解析为什么 keys 是必须的](/docs/reconciliation.html#recursing-on-children) 可以参考。
136136

137137
### 用 Keys 提取组件 {#extracting-components-with-keys}
138138

139-
元素的 Key 只有放在其周围数组的上下文中才有意义
139+
元素的 Key 只有放在就近的数组上下文中才有意义
140140

141-
比方说,如果你[抽取](/docs/components-and-props.html#extracting-components) 出一个 `ListItem` 组件,你应该把 key 保存在数组中的这个 `<ListItem />` 元素上,而不是放在 `ListItem` 组件中的 `<li>` 元素上。
141+
比方说,如果你[抽取](/docs/components-and-props.html#extracting-components) 出一个 `ListItem` 组件,你应该把 key 保留在数组中的这个 `<ListItem />` 元素上,而不是放在 `ListItem` 组件中的 `<li>` 元素上。
142142

143143
** 例子:不正确的使用键的方式 **
144144

@@ -204,7 +204,7 @@ ReactDOM.render(
204204

205205
[在 CodePen 上尝试](https://codepen.io/gaearon/pen/ZXeOGM?editors=0010)
206206

207-
一个好的经验法则是:在 `map()` 方法中的元素需要设置键属性
207+
一个好的经验法则是:在 `map()` 方法中的元素需要设置 keys 属性
208208

209209
### 键(Key)只是在兄弟节点之间必须唯一 {#keys-must-only-be-unique-among-siblings}
210210

@@ -280,7 +280,7 @@ function NumberList(props) {
280280
}
281281
```
282282

283-
JSX 允许在大括号中[嵌入任何表达式](/docs/introducing-jsx.html#embedding-expressions-in-jsx)所以我们可以在 `map()` 中这样使用
283+
JSX 允许在大括号中[嵌入任何表达式](/docs/introducing-jsx.html#embedding-expressions-in-jsx)所以我们可以内联 `map()` 返回的结果
284284

285285
```js{5-8}
286286
function NumberList(props) {

0 commit comments

Comments
 (0)