October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

SVG to React Components: What Changes in JSX vs. TSX

SVG-to-React conversion changes XML attribute names and style syntax for JSX. TSX adds a .tsx file, TypeScript JSX configuration, and type checking.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Converting SVG markup for React means adapting XML-style attributes and inline styles to JSX conventions. TSX uses the same JSX syntax, but adds TypeScript’s file, compiler-configuration, and type-checking requirements.

What changes when SVG becomes JSX?

JSX is markup-like syntax embedded in JavaScript. React treats JSX attributes as keys in JavaScript objects, so some SVG and HTML spellings must change.

As an Amazon Associate I earn from qualifying purchases.

SVG or XML JSX Reason
class="icon" className="icon" React uses className for the class prop.
stroke-width="2" strokeWidth="2" Most SVG prop names use camelCase.
fill-rule="evenodd" fillRule="evenodd" SVG prop names use camelCase.
aria-label="Search" aria-label="Search" ARIA attributes retain their dashed spelling.
data-kind="icon" data-kind="icon" Data attributes retain their dashed spelling.
xlink:href="#shape" xlinkHref="#shape" React uses a name without the colon for this namespaced attribute.
style="fill: red; stroke-width: 2" style={{ fill: 'red', strokeWidth: 2 }} The React style prop takes an object with camelCase CSS property names.

React also documents corresponding forms for other xml:* and namespace attributes. Check the applicable React DOM reference for any less common attributes in your SVG. These examples cover syntax changes, not a guarantee that every SVG construct converts correctly without review.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How does TSX differ from JSX?

TSX is TypeScript source that contains JSX. It keeps the same JSX attribute conventions; the differences are in the file extension, compiler setup, and type checking.

File and compiler configuration

Put JSX-containing TypeScript in a .tsx file and enable TypeScript’s jsx compiler option. The selected mode affects whether JSX is preserved or transformed and what output is produced. Modes documented by TypeScript include preserve, react, react-jsx, react-jsxdev, and react-native. Use the mode configured for your project rather than assuming one universal output.

Attribute and component checking

TypeScript checks lowercase intrinsic elements such as SVG tags through JSX element definitions. For value-based elements such as React components, it checks attributes against the component’s props typing. React typings provide the JSX definitions used for React. As a result, the props interface you choose determines which attributes callers can pass to a reusable SVG component.

Convert an SVG and review the component

  1. Choose how to use the artwork. Keep it as an external image if it only needs to be displayed as a static asset; convert it to inline JSX when it needs inline styling or component-level behavior. React does not require every SVG to become a component.
  2. Convert the markup. Change names such as class and stroke-width to their JSX forms, retain dashed aria-* and data-* attributes, and convert namespaced attributes such as xlink:href to React’s documented spelling.
  3. Convert inline styles. Replace an SVG style string with an object for the React style prop, using camelCase CSS property names.
  4. For TSX, check the project setup. Confirm the source file has a .tsx extension, the TypeScript jsx option is enabled, and the project has the React typings it uses.
  5. Design the component API. Decide deliberately whether callers should be able to pass values such as className, sizing, or event handlers. There is no single required prop signature for an SVG wrapper.
  6. Check the rendered result and accessibility. Choose a meaningful accessible name or a decorative treatment according to the icon’s purpose and surrounding content. The right treatment depends on context; syntax conversion alone does not decide it.

React recommends using a converter for existing HTML and SVG, while noting that understanding the JSX conventions is useful. A converter can handle routine syntax edits, but inspect the resulting markup and component behavior in your target React and TypeScript setup.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Which should you use: JSX or TSX?

Consideration JSX TSX
Project language JavaScript project using JSX TypeScript project containing JSX
Source file JavaScript file with JSX, according to the project setup .tsx
Configuration Use the project’s existing JSX build setup TypeScript jsx option must be enabled; its mode affects output
Attribute checking No TypeScript JSX attribute checking Intrinsic SVG attributes and component props are checked through JSX types

Choose based on the language and build pipeline already used by the codebase. TSX is useful when typed component props and attribute checking fit the project; the SVG’s visible JSX syntax does not otherwise change just because the file is TypeScript.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.