SVG processors like SVGO optimize SVG ids which often results in duplicated ids across multiple SVGs. This library tries to fix that by wrapping SVGs in a component that replaces all children ids and id references (`#id`, `url(#id)`) with unique generated ids like `___SVG_ID__10__0___`, ensuring no id collisions when multiple SVGs are rendered on the same page. Current stable version is 1.0.4. Release cadence is low (last release 2019). Key differentiators: lightweight, TypeScript types included, no external dependencies beyond React. For versions prior to 1.0.0, the library used a different API (package name `react-svg-unique-id` > 1.0.0).
npm install react-unique-svg-idVerified import paths — ran on the pinned version, not inferred.
Wraps an SVG with the SVGUniqueID component to ensure all ids are unique, avoiding collisions when multiple SVGs are rendered on the same page.
Use `import { SVGUniqueID } from 'react-svg-unique-id'` instead of `import SVGUniqueID from 'react-svg-unique-id'`.Ensure all ids are on direct children of the SVG, or consider manually handling nested SVGs.
Ids are sequential per render, but may not be stable across server-side rendering (SSR) if executed multiple times.
Consider forking or switching to an alternative if you encounter issues with React 18+.
Use xlinkHref for React <16, or use href for React >=16 and ensure the library handles both.
Use `import { SVGUniqueID } from 'react-svg-unique-id'`Run `npm install react-svg-unique-id` or `yarn add react-svg-unique-id`
Ensure you have installed the package and that your tsconfig includes 'jsx': 'react-jsx' or similar.