# Warning: Encountered two children with the same key, `duplicate`. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.

- **ID:** `react/duplicate-key-in-list`
- **Domain:** react
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

When rendering a list with .map(), two or more items have the same key prop, violating the requirement that keys must be unique among siblings.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| React 16.8+ | active | — | — |
| React 17.0.2 | active | — | — |
| React 18.2.0 | active | — | — |

## Workarounds

1. **Use a unique identifier from your data as the key: data.map(item => <Component key={item.id} />). If no unique ID exists, generate one when data is created (e.g., using uuid).** (95% success)
   ```
   Use a unique identifier from your data as the key: data.map(item => <Component key={item.id} />). If no unique ID exists, generate one when data is created (e.g., using uuid).
   ```
2. **If the data has duplicate IDs, deduplicate the array before rendering: const uniqueData = Array.from(new Map(data.map(item => [item.id, item])).values());** (85% success)
   ```
   If the data has duplicate IDs, deduplicate the array before rendering: const uniqueData = Array.from(new Map(data.map(item => [item.id, item])).values());
   ```

## Dead Ends

- **Using the array index as the key** — While this suppresses the warning, using index as key can cause incorrect component behavior if the list order changes (e.g., sorting, filtering). (40% fail)
- **Generating a random key on each render (e.g., Math.random())** — Random keys cause React to remount all components on every render, losing state and causing performance degradation. (70% fail)
- **Concatenating index with another value (e.g., key={`${index}-${item.id}`})** — This works if item.id is unique, but if not, the concatenation may still produce duplicates. Better to use a truly unique identifier. (30% fail)
