SVG to JSX / React
React / SVGConvert raw SVG code into production-ready React JSX or TypeScript TSX components. Auto-converts attributes, wraps in typed components, and provides live vector preview.
About This Tool
Converts a raw SVG icon or graphic into a React component: kebab-case SVG attributes get their camelCase
JSX names, the root <svg> can take a {...props} spread, and the whole
thing is wrapped in an exported function (or forwardRef) component. A live preview renders
the pasted SVG inline so you can check it before converting.
For converting general HTML markup rather than a standalone SVG, use
HTML to JSX / React instead; this tool's preview, currentColor
recoloring, and forwardRef option are SVG-specific and don't apply there.
Key Features
- forwardRef toggle: swaps the plain function component for a
React.forwardRef<SVGSVGElement>wrapper. - Component Name field: names the exported function and the file produced by Download.
- Live SVG preview: renders the pasted markup inline as you type, separate from the JSX output panel.
- currentColor toggle: recolors hardcoded
fill/strokevalues so the icon inherits surrounding text color. - Independent Wrap/TypeScript toggles: get a bare typed fragment or a full untyped component, or anything in between.
Example
Paste this SVG with Wrap in Component and TypeScript (TSX) checked, Component Name Icon:
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" class="icon" stroke-width="2"><path d="M4 4h8v8H4z"></path></svg>
produces:
import type { SVGProps } from 'react';
export function Icon(props: SVGProps<SVGSVGElement>) {
return (
<svg {...props} xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" className="icon" strokeWidth="2"><path d="M4 4h8v8H4z"></path></svg>
);
}
export default Icon; FAQ
- Which SVG attributes get converted?
class, inlinestylestrings, and kebab-case SVG attributes (stroke-width,fill-rule,clip-path,font-size,xlink:href, and more) are mapped to their camelCase JSX equivalents.- What does "Wrap in Component" add?
- It spreads
{...props}onto the root<svg>tag and wraps the markup in an exported function component (or aReact.forwardRefcomponent when forwardRef is on) named after Component Name. - What does the currentColor option do?
- It replaces any hardcoded
fillorstrokevalue (exceptnone,transparent, andcurrentColoritself) withcurrentColor, so the icon inherits the surrounding text color. - JSX or TSX output?
- Toggling TypeScript (TSX) switches between a typed
SVGProps<SVGSVGElement>component and a plain JavaScript one, and the Download button's file extension follows the same toggle. - Is the live preview safe for untrusted SVG?
- The preview renders your pasted markup directly in your own browser tab. Don't paste SVG from sources you don't trust.