This product is not supported for your selected Datadog site. ().
Metadata
ID:tsx-react/tsx-key
Language: TypeScript
Severity: Error
Category: Error Prone
Description
In React, each JSX element rendered within a list or an iterator (such as Array.prototype.map()) requires a unique and stable key prop. This key helps React efficiently identify which items have changed, are added, or are removed during updates. Failing to provide a key can lead to performance issues, unexpected rendering behavior, incorrect component state, and stale UI, especially when list items are reordered, filtered, or added/removed.
How to Remediate
To fix this, provide a unique and stable key prop to each top-level JSX element returned within a list or iterator. Ideally, the key should be a unique identifier from your data (e.g., item.id). Avoid using array indices as keys if the list items can change order, be filtered, or be added/removed, as this can negate the benefits of keys. Note that React Fragment shorthand (<>...</>) does not support the key prop; for keyed fragments, use React.Fragment explicitly (e.g., <React.Fragment key={item.id}>...</React.Fragment>).