mirror of
https://github.com/airbnb/javascript.git
synced 2026-04-25 03:00:19 -04:00
Avoid using an array index as key prop, prefer unique ID
This commit is contained in:
@@ -279,6 +279,26 @@
|
||||
<div />
|
||||
```
|
||||
|
||||
- Avoid using an array index as `key` prop, prefer a unique ID. ([why?](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318))
|
||||
|
||||
```jsx
|
||||
// bad
|
||||
{todos.map((todo, index) =>
|
||||
<Todo
|
||||
{...todo}
|
||||
key={index}
|
||||
/>
|
||||
)}
|
||||
|
||||
// good
|
||||
{todos.map((todo) =>
|
||||
<Todo
|
||||
{...todo}
|
||||
key={todo.id}
|
||||
/>
|
||||
)}
|
||||
```
|
||||
|
||||
## Parentheses
|
||||
|
||||
- Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md)
|
||||
|
||||
Reference in New Issue
Block a user