We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3b1c9dc commit e30a9d0Copy full SHA for e30a9d0
react/README.md
@@ -280,6 +280,25 @@
280
// good
281
<div />
282
```
283
+ - 避免使用数组的index来作为属性`key`的值,推荐使用唯一ID. ([为什么?](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318))
284
+
285
+ ```jsx
286
+ // bad
287
+ {todos.map((todo, index) =>
288
+ <Todo
289
+ {...todo}
290
+ key={index}
291
+ />
292
+ )}
293
294
+ // good
295
+ {todos.map(todo => (
296
297
298
+ key={todo.id}
299
300
+ ))}
301
+ ```
302
303
## Parentheses 括号
304
0 commit comments