File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ ReactDOM.render(
42
42
);
43
43
```
44
44
45
- [ 在 CodePen 上试试。 ] ( https://codepen.io/gaearon/pen/GjPyQr?editors=0011 )
45
+ [ 在 CodePen 上尝试 ] ( https://codepen.io/gaearon/pen/GjPyQr?editors=0011 )
46
46
47
47
这段代码生成了一个 1 到 5 的数字列表。
48
48
@@ -94,7 +94,7 @@ ReactDOM.render(
94
94
);
95
95
```
96
96
97
- [ 在 CodePen 上试试。 ] ( https://codepen.io/gaearon/pen/jrXYRR?editors=0011 )
97
+ [ 在 CodePen 上尝试 ] ( https://codepen.io/gaearon/pen/jrXYRR?editors=0011 )
98
98
99
99
## Keys {#keys}
100
100
@@ -202,7 +202,7 @@ ReactDOM.render(
202
202
);
203
203
```
204
204
205
- [ 在 CodePen 上试试。 ] ( https://codepen.io/gaearon/pen/ZXeOGM?editors=0010 )
205
+ [ 在 CodePen 上尝试 ] ( https://codepen.io/gaearon/pen/ZXeOGM?editors=0010 )
206
206
207
207
一个好的经验法则是:在 ` map() ` 方法中的元素需要设置键属性。
208
208
@@ -246,7 +246,7 @@ ReactDOM.render(
246
246
);
247
247
```
248
248
249
- [ 在 CodePen 上试试。 ] ( https://codepen.io/gaearon/pen/NRZYGN?editors=0010 )
249
+ [ 在 CodePen 上尝试 ] ( https://codepen.io/gaearon/pen/NRZYGN?editors=0010 )
250
250
251
251
key 会传递信息给 React ,但不会传递给你的组件。如果你的组件中需要使用 ` key ` 属性的值,请用其他属性名显式传递这个值:
252
252
@@ -296,6 +296,6 @@ function NumberList(props) {
296
296
}
297
297
```
298
298
299
- [ 在 CodePen 上试试。 ] ( https://codepen.io/gaearon/pen/BLvYrB?editors=0010 )
299
+ [ 在 CodePen 上尝试 ] ( https://codepen.io/gaearon/pen/BLvYrB?editors=0010 )
300
300
301
301
这么做有时可以使你的代码更清晰,但有时这种风格也会被滥用。就像在 JavaScript 中一样,何时需要为了可读性提取出一个变量,这完全取决于你。但请记住,如果一个 ` map() ` 嵌套了太多层级,那可能就是你 [ 提取出组件] ( /docs/components-and-props.html#extracting-components ) 的一个好时机。
You can’t perform that action at this time.
0 commit comments