Skip to content

Commit 7a94b7f

Browse files
author
zhaozhiming
committed
docs(cn): add whitespace in English word
1 parent b7b6bcb commit 7a94b7f

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

content/docs/lists-and-keys.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ 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];
1515
const doubled = numbers.map((number) => number * 2);
1616
console.log(doubled);
1717
```
1818

19-
代码打印出`[2, 4, 6, 8, 10]`
19+
代码打印出 `[2, 4, 6, 8, 10]`
2020

2121
在 React 中,把数组转化为列表[元素](/docs/rendering-elements.html) 的过程是相似的。
2222

2323
### 渲染多个组件
2424

25-
你可以通过使用`{}`在 JSX 内构建一个[元素集合](/docs/introducing-jsx.html#embedding-expressions-in-jsx)
25+
你可以通过使用 `{}` 在 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];
@@ -33,7 +33,7 @@ const listItems = numbers.map((number) =>
3333
);
3434
```
3535

36-
我们把整个`listItems`插入到`<ul>`元素中,然后[渲染进 DOM](/docs/rendering-elements.html#rendering-an-element-into-the-dom)
36+
我们把整个 `listItems` 插入到 `<ul>` 元素中,然后[渲染进 DOM](/docs/rendering-elements.html#rendering-an-element-into-the-dom)
3737

3838
```javascript{2}
3939
ReactDOM.render(
@@ -130,17 +130,17 @@ const todoItems = todos.map((todo, index) =>
130130
);
131131
```
132132

133-
如果列表项目的顺序可能会变化,我们不建议使用索引来用作键值,因为这样做会导致性能的负面影响,还可能引起组件状态问题。如果你想要了解更多,请点击[深度解析 key 的必要性](/docs/reconciliation.html#递归子节点)。如果你选择不指定显式的键值,那么 React 将默认使用索引用作为列表项目的键值。
133+
如果列表项目的顺序可能会变化,我们不建议使用索引来用作键值,因为这样做会导致性能的负面影响,还可能引起组件状态问题。如果你想要了解更多,请点击[深度解析 key 的必要性](/docs/reconciliation.html# 递归子节点)。如果你选择不指定显式的键值,那么 React 将默认使用索引用作为列表项目的键值。
134134

135135
要是你有兴趣了解更多的话,这里有一篇文章 [in-depth explanation about why keys are necessary](https://reactjs.org/docs/reconciliation.html#recursing-on-children) 可以参考。
136136

137137
### 用 Keys 提取组件
138138

139139
元素的 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

143-
**示范:不正确的使用键的方式**
143+
** 示范:不正确的使用键的方式 **
144144

145145
```javascript{4,5,14,15}
146146
function ListItem(props) {
@@ -174,7 +174,7 @@ ReactDOM.render(
174174
```
175175

176176

177-
**示范:正确的使用键的方式**
177+
** 示范:正确的使用键的方式 **
178178

179179
```javascript{2,3,9,10}
180180
function ListItem(props) {
@@ -205,7 +205,7 @@ ReactDOM.render(
205205

206206
[在 CodePen 上试试。](https://codepen.io/rthor/pen/QKzJKG?editors=0010)
207207

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

210210
### 键(key)只是在兄弟节点之间必须唯一
211211

@@ -249,7 +249,7 @@ ReactDOM.render(
249249

250250
[在 CodePen 上试试。](https://codepen.io/gaearon/pen/NRZYGN?editors=0010)
251251

252-
key 会传递信息给 React ,但不会传递给你的组件。如果你的组件中需要使用`key`属性的值,请用其他属性名显式传递这个值:
252+
key 会传递信息给 React ,但不会传递给你的组件。如果你的组件中需要使用 `key` 属性的值,请用其他属性名显式传递这个值:
253253

254254
```js{3,4}
255255
const content = posts.map((post) =>
@@ -260,11 +260,11 @@ const content = posts.map((post) =>
260260
);
261261
```
262262

263-
上面例子中,`Post`组件可以读出`props.id`,但是不能读出`props.key`
263+
上面例子中,`Post` 组件可以读出 `props.id`,但是不能读出 `props.key`
264264

265265
### 在 JSX 中嵌入 map()
266266

267-
在上面的例子中,我们声明了一个单独的`listItems`变量并将其包含在 JSX 中:
267+
在上面的例子中,我们声明了一个单独的 `listItems` 变量并将其包含在 JSX 中:
268268

269269
```js{3-6}
270270
function NumberList(props) {
@@ -281,7 +281,7 @@ function NumberList(props) {
281281
}
282282
```
283283

284-
JSX 允许在大括号中[嵌入任何表达式](/docs/introducing-jsx.html#embedding-expressions-in-jsx),所以我们可以在`map()`中这样使用:
284+
JSX 允许在大括号中[嵌入任何表达式](/docs/introducing-jsx.html#embedding-expressions-in-jsx),所以我们可以在 `map()` 中这样使用:
285285

286286
```js{5-8}
287287
function NumberList(props) {
@@ -299,4 +299,4 @@ function NumberList(props) {
299299

300300
[在 CodePen 上试试。](https://codepen.io/gaearon/pen/BLvYrB?editors=0010)
301301

302-
这么做有时可以使你的代码更清晰,但有时这种风格也会被滥用。就像在 JavaScript 中一样,何时需要为了可读性提取出一个变量,这完全取决于你。但请记住,如果一个`map()`嵌套了太多层级,那可能就是你[提取出组件](/docs/components-and-props.html#提取组件)的一个好时机。
302+
这么做有时可以使你的代码更清晰,但有时这种风格也会被滥用。就像在 JavaScript 中一样,何时需要为了可读性提取出一个变量,这完全取决于你。但请记住,如果一个 `map()` 嵌套了太多层级,那可能就是你 [提取出组件](/docs/components-and-props.html# 提取组件) 的一个好时机。

0 commit comments

Comments
 (0)