Skip to content

Commit

Permalink
[guide] [react] Explain use of ID over key right on page
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinweber authored and ljharb committed Aug 27, 2018
1 parent 5443d03 commit 48448a8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ This style guide is mostly based on the standards that are currently prevalent i
<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))
- Avoid using an array index as `key` prop, prefer a stable ID.

> Why? Not using a stable ID [is an anti-pattern](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318) because it can negatively impact performance and cause issues with component state.

We don’t recommend using indexes for keys if the order of items may change.

```jsx
// bad
Expand Down

0 comments on commit 48448a8

Please sign in to comment.