Skip to content

Commit e30a9d0

Browse files
committed
sync react readme with upstream
1 parent 3b1c9dc commit e30a9d0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

react/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,25 @@
280280
// good
281281
<div />
282282
```
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+
<Todo
297+
{...todo}
298+
key={todo.id}
299+
/>
300+
))}
301+
```
283302

284303
## Parentheses 括号
285304

0 commit comments

Comments
 (0)