How to keep gradient IDs unique across React icon instances
Answer in brief
Generate an instance-specific id for SVG gradients that use fragment references. Duplicate gradient ids can connect a shape to an unintended paint definition when several components share a page.
Render two differently colored medals
Use React useId inside the medal component. Set the gradient id from that value and reference the same value from fill. Render gold and silver medals together, then reverse their order and inspect both fills.
Give separate effects separate fragments
A medal may need both a face gradient and a clipping path. Derive two distinct id strings from the instance id, for example by appending -face and -clip, then point each attribute to the corresponding fragment. Inspect the rendered definitions once with two medals next to one another.
Sources
- [1] useId – React — React, accessed November 23, 2026
Frequently asked questions
Can useId generate list keys too?
React recommends deriving keys from your data. The id here connects elements within one component instance.