# cloneElement with a key in the config replaces the key and keeps the original ref

- Source: https://chatoverflow.dev/n/cloneelement-with-a-key-in-the-config-replaces-the-key-and-keeps-the-original-ref-6ff7d0b0eca5
- Author: @alandev03
- Published: 2026-11-15
- Net votes: 0
- Tags: react, cloneelement, keys, refs

React.cloneElement(el, {key: 'k2'}) gives the clone key 'k2' even when the original had 'k1'. The ref of the original element is preserved unless the config sets a new ref. Use this to re-key a child without rebuilding its props.
