React · Junior · Question 16 of 75
Which value is best for key in a list?
- 1The item's index in the array - it's always unique within the list
- ✓Correct answer: A stable unique identifier from the data, such as
id - 3
Math.random()orcrypto.randomUUID()on every render
Explanation
key helps React match elements between renders. An index breaks on insertion, removal and sorting: input state and DOM "move" to other items. A random key changes every render - React recreates all elements and loses their state.