Skip to content

Files

Latest commit

 

History

History
21 lines (15 loc) · 534 Bytes

jsx-key.md

File metadata and controls

21 lines (15 loc) · 534 Bytes

Pattern: Missing key prop in array element

Issue: -

Description

React requires a unique key prop for elements within arrays to efficiently track changes and handle updates. Without keys, React cannot identify which items have changed, been added, or been removed.

Examples

Example of incorrect code:

[1, 2, 3].map((x) => <App />);
[1, 2, 3]?.map((x) => <BabelEslintApp />);

Example of correct code:

[1, 2, 3].map((x) => <App key={x} />);
[1, 2, 3]?.map((x) => <BabelEslintApp key={x} />);