
SVG to React: From Raw File to Production-Ready Component
Convert SVG icons to React/JSX components, optimize them and ship in your design system.
Why move from raw SVG to a React component
Pasting inline SVG into JSX often breaks on the first build: HTML attributes (`class`, `stroke-width`) are invalid in React, embedded `<style>` tags are hard to maintain, and Figma exports bloat file size. The online SVG to JSX converter turns a `<svg>` file into a copy-ready React component — with attribute renames (`className`, `strokeWidth`), a custom component name, and an optional TypeScript mode. The full workflow runs in the browser on the online SVG tools hub, with no account or server upload. For optimization context, see also SVGO presets explained.
Example: UI icon in a design system
A 24×24 icon exported from Figma may weigh 3–6 KB as raw SVG. After optimize default, often 1–2 KB. Generated JSX stays readable — use the <a href="/en/beautify-svg" class="text-primary hover:underline">online SVG beautifier</a> on intermediate markup if you need to audit paths.
Before optimization
After optimization
Each imported icon component lands in your app's JavaScript chunk — unlike a static `.svg` file. That's the usual React trade-off; the <a href="/en/minify-js" class="text-primary hover:underline">online JavaScript minifier</a> illustrates JS-side compression, but the first line of defense is a lean SVG source before conversion.
Best practices: props, className and accessibility
The converter maps `class` → `className` and kebab-case SVG attributes to React camelCase. For consistent theming, edit source SVG or JSX to use `fill="currentColor"` and control color via CSS/Tailwind on the parent.
An icon beside visible text is decorative → `aria-hidden="true"` on `<svg>`. An icon that carries meaning (e.g. error status without text) needs `<title>` / `<desc>` or an explicit `aria-label`. FastMinify preserves title/desc on optimize; verify they survive conversion.
Invalid component names (`icon-arrow`) → silent fallback to `SvgIcon` (the tool reports fallback). Invalid XML or multiple roots → parse error. Duplicate IDs if you inline the same component multiple times without a sprite.
When the browser tool is enough
No need to install SVGR to convert one icon from Slack or a one-off Figma export.
Limits: SVGR and bundler plugins
Online conversion is ideal to explore and ship a few components. Automatic `import Icon from './icon.svg'` on every build, batching an `icons/` folder, and custom SVGR templates remain the domain of `@svgr/cli`, `@svgr/webpack`, or `vite-plugin-svgr`.
Validate name, export, and JSX structure in svg-to-jsx, then mirror conventions in SVGR. Optimize with the same SVGO preset as CI — see <a href="/en/blog/svgo-presets-optimize-svg-web" class="text-primary hover:underline">SVGO presets</a> and the <a href="/en/blog/svg-optimization-guide-web" class="text-primary hover:underline">SVG optimization guide</a>.
SVGR and the React ecosystem
FastMinify svg-to-jsx covers paste → copy JSX with three options. The npm ecosystem offers more flexibility for automation.
@svgr/cli
SVGR command line — reference for batch and CI.
Pros:
Cons:
vite-plugin-svgr / @svgr/webpack
Import SVG as React component at compile time.
Pros:
Cons:
FastMinify optimize-svg + svg-to-jsx
Browser chain optimize → convert, no install.
Pros:
Cons:
Inline SVG, `<img>`, or React component?
The choice affects styling, accessibility, and JavaScript bundle size. A React component fits reusable icons in a design system; one-off inline or `<img src="icon.svg">` remains valid for simple cases.
UI icons (buttons, nav), themeable logos (`fill="currentColor"`), or assets shared across React/Next.js apps. The component encapsulates markup and avoids duplicating 200 lines of `<path>` on every page.
svg-to-jsx produces JSX from existing markup. It does not resolve Sass `@use`, multi-file partials, or automatic generation on every commit — SVGR in CI still applies there. The online tool excels at prototyping, fixing an export, or onboarding a designer.
FastMinify workflow: optimize then svg-to-jsx
An Illustrator or Figma export often carries metadata and excessive precision. Run the online SVGO optimizer first (safe or default preset for UI icons), or the SVG minifier for whitespace-only cleanup. You shrink the final component without changing the React workflow.
Paste the optimized SVG into the SVG to JSX tool. Pick the component name (must start with uppercase — otherwise falls back to `SvgIcon`), default vs named export, and TypeScript if your codebase uses `.tsx`.
After copy, wrap as needed: merge `props` onto `<svg>` (`{...props}`), add `aria-hidden` for decorative icons, or `role="img"` + `aria-label` for informative ones. Validate with validate SVG online on source markup before conversion.
Conclusion
The safest path to a maintainable React component: optimize the source SVG, convert to JSX with explicit options, then adjust props and accessibility in your design system. FastMinify chains optimize-svg and svg-to-jsx entirely in the browser — ideal to prototype before locking SVGR in CI.
Related Articles

Safe, default or aggressive? Pick the right SVGO preset and optimize SVG for production.

Check `compose.yml` and `.env` structure before `docker compose up` — no local tooling required.

Catch Docker anti-patterns and format Dockerfiles before CI with browser-based lint and format tools.