What is the significance of key attribute in React lists?
From:
React JS Coding Interview Questions
,
Medium Level Coding Questions and Answers
Last Updated: 10 months ago
// The key attribute is used to uniquely identify elements
// in a list of React components. When React renders a list,
// it uses the key attribute to efficiently update and reorder
// components without re-rendering the entire list. Keys should
// be unique among siblings but don't need to be globally unique.
const myList = [1, 2, 3];
const listItems = myList.map(number => (
<li key={number}>{number}</li>
));
// Render the list
<ul>{listItems}</ul>