API reference

All four exports share the props table below, with the exceptions noted per export.

<SvgIn />

From svgin-react/client or svgin-react/server. The server version's onMount and loading are no-ops (no DOM to hand back, no loading state to defer).

<SvgInSuspense />

From svgin-react/client. Suspends via React 19's use() instead of managing loading/error state itself. Does not accept fallback, loadingFallback, or loading - pair it with a real <Suspense> boundary and an error boundary instead. See the live demo.

<SvgInProvider />

From svgin-react/client. Sets shared className, fallback, loadingFallback, onError, sanitizeFn, disableSanitization, and loading defaults for every <SvgIn /> beneath it. A prop passed directly to a given <SvgIn /> always wins. Not read by <SvgInSuspense />. See the live demo.

preloadSvg(url, options?)

From svgin-react/core. Fetches and caches an SVG ahead of render, so the eventual <SvgIn src={url} /> resolves instantly from cache. Accepts sanitizeFn and disableSanitization.

import { preloadSvg } from 'svgin-react/core';

preloadSvg('/icons/alert.svg');

Shared props

PropTypeNotes
srcstringURL to fetch. Ignored if svg is also given. src or svg is required.
svgstringRaw SVG markup, sanitized and rendered directly. Takes precedence over src.
width / heightnumber | string
fillstring
classNamestring
ariaLabelstring
title / descriptionstringInjects a <title>/<desc> into the rendered SVG.
fallbackReactNodeRendered on fetch/sanitize failure. Not used by SvgInSuspense.
loadingFallbackReactNodeClient component only. Rendered while pending, instead of the default placeholder.
sanitizeFn(svg: string) => Promise<string>Overrides the default DOMPurify sanitizer.
disableSanitizationbooleanSkip sanitization entirely. Only for markup you already trust.
onError(error: Error) => voidCalled on fetch/sanitize failure, alongside fallback.
onMount(svg: SVGSVGElement) => voidClient component only. Called after the SVG mounts or updates.
loading'eager' | 'lazy'Client component only. 'lazy' defers fetch/sanitize until near the viewport.