A key prop is the identifier React uses to track items in a list across renders. Stable keys help React match elements to the correct component instance during reconciliation. If keys are missing, unstable, or based on array position, React may misapply state when items are reordered, added, or removed.
What a key prop actually does
In React, a key prop gives each item in a rendered list a stable identity across renders. That identity helps the reconciliation process determine which component instance should be updated, reused, or removed when list order changes.
Keys are not visible UI content and they are not general-purpose IDs for your application data. Their job is to help React preserve the relationship between rendered elements and component state.
Why stable keys matter
Stable keys reduce the chance that React will treat one item as if it were another. When keys are derived from durable data, React can track inserts, deletes, and reordering more accurately, which keeps local state attached to the right item.
Unstable keys, especially array indexes in dynamic lists, can cause state to move unexpectedly between rows. That can produce subtle UI defects such as edited values appearing under the wrong item, focus jumping, or stale component state surviving longer than it should.
How React uses keys during reconciliation
During reconciliation, React compares the previous render with the next one and uses keys to match siblings in a list. A matching key tells React that the element represents the same logical item, even if its position in the array changed.
When a list item keeps the same key, React can preserve component state and avoid unnecessary remounts. When the key changes, React treats the element as a different instance, which is useful only when you truly want to reset that subtree.
Common mistakes and better patterns
The most common mistake is using the array index as a key in a list that can reorder, filter, insert, or delete items. That pattern is only safe when the list is static and the item order never changes.
A better pattern is to use a stable identifier from the underlying data, such as a database ID, UUID, or other durable item identifier. If no natural ID exists, the data model usually needs one before the UI can track items reliably.
Risk and Threat Considerations
Incorrect keys are usually a correctness problem first, but they can become a trust and integrity issue in stateful interfaces. If state is misapplied across rows, users may act on the wrong record, submit the wrong edit, or misread which item was actually changed.
Failure mechanism: React reuses component instances based on the key, so unstable or duplicate keys can attach preserved state, event handlers, or local input values to the wrong list item after a reorder or filter.
Impact: The UI can silently display misleading data, corrupt user actions, or create hard-to-detect bugs that only appear when list structure changes.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP ASVS, NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP ASVS | V15 — Secure Coding and Architecture | Key choice affects component state integrity in rendered UI lists. |
| Recommendation — Use stable identifiers for list items to preserve component state across renders. | ||
| NIST SP 800-53 Rev 5 | SI-10 — Information Input Validation | Correct item identity prevents unintended state and data handling in UI input flows. |
| Recommendation — Validate list item identity so UI updates apply to the intended record. | ||
| CIS Controls v8 | CIS-16 — Application Software Security | React key usage is a frontend application security and correctness concern. |
| Recommendation — Review frontend list rendering patterns to prevent state mismatch bugs. | ||
Practitioner Guidance
What to watch for: Treat key choice as part of component correctness, not a cosmetic implementation detail. If a list can change order or membership, use a stable item identifier and verify that the key stays consistent for the same logical record across renders.
Practitioner takeaway: If the key changes when the item has not meaningfully changed, React will likely treat it as a different component and your UI state may drift.
Related resources from NHI Mgmt Group
- What are the key NHI security metrics every CISO should track?
- What is the difference between role-based access and API key governance for NHI security?
- When does a short-lived API key still create material risk?
- What is the difference between API-key security and hardware-bound identity for AI agents?
Deepen Your Knowledge
Reviewed and updated by the NHIMG editorial team on September 29, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org