SVGSketch Learn

How to Export SVG as a React Component

Skip SVGR. Copy a production-ready React component straight from the editor, or generate typed TSX in CI with the CLI.

Open SVGSketch

Quick answer

Open the SVG in SVGSketch and choose Edit > Copy as Code > React (JSX) - the component lands on your clipboard ready to paste (a Pro feature). For TypeScript output or CI generation, use the CLI: svgsketch codegen icon.svgs -f react -o Icon.tsx --typescript.

Steps at a glance

  1. Open and clean the SVG

    Drag the .svg onto SVGSketch and clean up groups and defs.

  2. Copy as React code

    Edit > Copy as Code > React (JSX). Pro feature.

  3. Paste into your codebase

    Import as a normal React component with className/style props.

  4. Use the CLI for TypeScript

    svgsketch codegen icon.svgs -f react -o Icon.tsx --typescript.

  5. Theme with currentColor

    Set fills to currentColor via the XML Inspector first.

Step 1: Open and clean the SVG

Drag the .svg onto app.svgsketch.com. Clean up stray groups and unused definitions first (Object > Clean Up Empty Groups, and SVGO options at export) so you ship a clean, minimal JSX tree rather than a literal copy of the original markup.

Step 2: Copy as React code

Choose Edit > Copy as Code > React (JSX). SVGSketch generates a self-contained function component and puts it on the clipboard. Vue (SFC), D3.js, and CSS + SVG targets sit in the same submenu, and plain SVG markup is Ctrl+Shift+C. The framework code targets are SVGSketch Pro features; SVG copy is free.

Step 3: Paste it into your codebase

Paste the component into your icon directory and import it like any React component. The output uses camelCase JSX attributes (strokeWidth, viewBox, fillRule) so it compiles without warnings, and the component accepts className and style props for styling from the call site.

Step 4: Use the CLI for TypeScript and CI

For typed output or automated pipelines, save the document as .svgs and run the CLI: svgsketch codegen icon.svgs -f react -o Icon.tsx --name Icon --typescript. The TypeScript mode emits a typed Props interface, and --var key=value fills template variables so one source can generate many themed variants.

Step 5: Theme with currentColor

To make the component inherit its color from CSS, set the artwork's fills to "currentColor" (via the XML Inspector, F12) before copying the code. Any color rule on the parent element then tints the icon - the standard pattern for icon systems that match button text color.

FAQ

Does SVGSketch generate TypeScript types?

Yes, via the CLI: svgsketch codegen with --typescript emits a .tsx component with a typed Props interface (className and style). The in-editor Copy as Code target is plain JSX.

Will the component support className and style props?

Yes. The generated component takes className and style props and applies them to the root <svg> element.

How is this different from SVGR?

SVGSketch handles optimization, color theming, and code generation without an extra build step or babel plugin. The output is closer to what a hand-written component would look like, and the same document also exports Vue, D3.js, and CSS.

Does it support Vue or other frameworks?

Yes. Vue (SFC), D3.js, and CSS + SVG are in the same Edit > Copy as Code submenu, and the CLI generates all of them with -f vue, -f d3, or -f css.

Can I batch generate components for a whole icon set?

Yes - script the CLI over your files: run svgsketch codegen per .svgs document in a loop or build step, one component file per source. The --fail-on-warnings flag makes it CI-safe.

Open your SVG in SVGSketch

Start with a blank canvas, import an SVG, or use the editor as a conversion and cleanup step.

Open SVGSketch