From c247fd754b779df744c1c8ce34eed0ef37f09893 Mon Sep 17 00:00:00 2001 From: Alanna Scott Date: Wed, 25 May 2016 12:07:36 -0700 Subject: [PATCH] Avoid using an array index as `key` prop, prefer unique ID --- react/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/react/README.md b/react/README.md index 747bbe65..3f21dd3b 100644 --- a/react/README.md +++ b/react/README.md @@ -279,6 +279,26 @@
``` + - 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) => + + )} + + // good + {todos.map((todo) => + + )} + ``` + ## 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)