How to Convert SVG Icons to React and Vue Components the Clean Way
Turn exported SVG icons into tidy React JSX/TSX or Vue 3 components: strip editor clutter, use currentColor, add a size prop and accessible titles.
How to Convert SVG Icons to React and Vue Components the Clean Way
Most icon sets start life in a design tool and end up in a component library. The trip between those two places is where things go wrong. Here is what changes along the way, and how to do it quickly in the browser. An SVG saved from Figma, Illustrator, Inkscape or Sketch is valid XML, but it is rarely valid JSX, and it usually carries far more markup than the browser needs to draw a 24-pixel arrow.
Why a raw SVG does not drop straight into React
SVG is an XML language, and React's JSX is JavaScript that only looks like markup. That difference shows up in the attribute names. In SVG you write class, stroke-width, fill-rule and xlink:href; in JSX these must become className, strokeWidth, fillRule and xlinkHref. An inline style="fill:red" string is not allowed either, because React expects a style object. Paste an unmodified export into a .jsx file and you get warnings at best and a broken build at worst.
Vue templates are more forgiving. They accept SVG attributes in their original spelling, so the main work for Vue is wrapping the markup in a single-file component and deciding which values should become props.
What editors leave behind
Design tools add things that help them reopen the file later but do nothing in a web page: an XML prolog, a doctype, comments, metadata blocks, editor-specific namespaces such as sodipodi and inkscape, ids on every group and coordinates with eight or more decimal places. Rounding numbers to two decimals is visually identical at icon sizes, and removing empty groups makes the markup readable again.
One caution matters here: some ids are not junk. A gradient, mask or clip path is referenced by url(#id) or href="#id", and deleting its id silently breaks the icon. A safe optimiser removes only ids that nothing points to.
Colour, size and accessibility
Three decisions turn a static picture into a reusable component.
- Colour. Replacing hard-coded fills and strokes with
currentColormakes the icon inherit the CSScolorof its parent, so the same component works in a dark header and a light card. - Size. A single
sizeprop that sets both width and height is easier than two props. A default of1emlets the icon scale with the surrounding text. - Accessibility. Decorative icons next to a visible label should be hidden from screen readers with
aria-hidden="true". An icon that carries meaning on its own, such as a bare trash-can button, needs a text alternative. The SVG 2 specification defines thetitleelement for this purpose, and linking it witharia-labelledbymakes the name reliable.
Converting icons with the tool
Open the SVG to React and Vue Component Converter and paste an SVG or open one or more files. Each file gets its own tab. Choose the number of decimals for rounding, switch on the currentColor option if the icon should follow text colour, and pick a target: React JSX, React TSX or Vue 3.
For React output the converter rewrites attribute names to their camelCase form, turns inline style strings into objects, applies the size prop to the root svg and spreads any remaining props onto it, so onClick, className and aria-* attributes still work. TSX output types the props as SVGProps<SVGSVGElement>, and you can wrap the component in forwardRef or memo if your design system needs refs. For Vue it writes a component with a template and a script setup block, with typed size and title props; other attributes from the parent fall through to the root element.
Turn on the title prop only for icons that need a name. The component then renders a title element with a generated id and links it, otherwise it adds aria-hidden.
For a whole set, open all the files at once. The batch table lists the size saving and any parse errors for each icon, and the ZIP download contains every component plus an index file that re-exports them by name, ready for import { ArrowRight } from "./icons".
A short example
Take an arrow exported from Sketch at under a kilobyte, with a comment, a title block, two nested groups and coordinates like 13.2928932. With two decimals and currentColor enabled, the cleaned markup is roughly half the size. The generated ArrowRight.tsx accepts size={24} or size={48}, and in the preview its fill changes as soon as the parent's text colour changes.
Tips and common mistakes
- Check the preview at several sizes before exporting; thin strokes can look different at 16 pixels.
- Do not use currentColor on multi-colour illustrations. It is meant for single-colour icons.
- Keep component names in PascalCase and file names consistent, so the index file stays predictable.
- Do not add a title to every icon "just in case". Duplicate announcements are as unhelpful as missing ones.
Limits
The optimiser is deliberately conservative. It does not merge paths, convert basic shapes to paths or remove hidden elements, so a dedicated optimiser such as SVGO can shrink complex artwork further. It does not sanitise embedded scripts or foreignObject content, so only convert SVGs you trust. SMIL animations are passed through unchanged rather than converted, and the tool does not decide which icons are decorative; that judgement stays with you.



