Skip to content

Files

Latest commit

 

History

History
19 lines (13 loc) · 496 Bytes

no-array-index-key.md

File metadata and controls

19 lines (13 loc) · 496 Bytes

Pattern: Array index as React key prop

Issue: -

Description

Using array indices as React keys can lead to incorrect component behavior when items are reordered or deleted. Keys should uniquely identify list items across re-renders, while array indices change based on item position.

Examples

Example of incorrect code:

things.map((thing, index) => <Hello key={index} />);

Example of correct code:

things.map((thing, index) => <Hello key={thing.id} />);