Skip to content

Sirv React components

By , Head of Sirv StudioUpdated

Open this page in a new chat

Short answer

Install @sirv/react from npm and wrap your app once in <SirvProvider> with your Sirv account alias. Then use SirvImage, SirvVideo, SirvSpin, SirvModel and the other components to add responsive images, videos, 360 spins, 3D models and galleries to any React app. It also includes a Next.js image loader.

After reading this you will know

  • How to install @sirv/react and set your alias once
  • Which component to use for each media type
  • How to use the Next.js loader and values stored in a CMS
React logo

Drop responsive Sirv images, videos, 360 spins, Sirv “views”, 3D models (.glb) and combined media-viewer galleries straight into any React app with the official @sirv/react package.

Faster image delivery makes your React UI feel snappier on every device and connection.

The @sirv/react components serve images at the perfect dimensions, in the optimal image format (often WebP or AVIF), from the nearest of 20 global CDN servers.

They come with native lazy loading and an auto-generated srcset baked in.

The package is zero-dependency (only react / react-dom as peers) and works with Next.js (App Router & Pages), Vite, Remix and Create React App.

It ships ESM + CJS + TypeScript types with a 'use client' boundary, so the components drop straight into React Server Component apps.

sirv.js is auto-loaded only when a spin / view / viewer needs it.

  1. Install the package with your favourite package manager:

    npm install @sirv/react
    # or
    pnpm add @sirv/react
    # or
    yarn add @sirv/react
  2. Wrap your app once in <SirvProvider> near the root (e.g. your root layout). Every nested Sirv component inherits the alias from context, so you set it in one place and never repeat it.

    import { SirvProvider, SirvImage } from '@sirv/react';
    export default function App() {
    return (
    <SirvProvider alias="demo.sirv.com" quality={82}>
    <SirvImage
    path="/products/shoe.jpg"
    width={800}
    height={600}
    alt="Product shoe"
    sizes="(min-width: 1024px) 50vw, 100vw"
    />
    </SirvProvider>
    );
    }

That’s it. The image is delivered with a responsive srcset, native lazy loading and optimal format negotiation - no extra wiring required.

The package exports seven components, each tuned for a specific media type:

  • <SirvImage> - responsive image (auto srcset + lazy), or sirv.js DPR-aware mode.
  • <SirvVideo> - Sirv-delivered video with a derived poster frame.
  • <SirvSpin> - 360° spin viewer (sirv.js).
  • <SirvView> - Sirv composite “view” (sirv.js).
  • <SirvModel> - 3D model viewer for .glb files (sirv.js).
  • <SirvMedia> - polymorphic; picks the right component from a value’s _type discriminator.
  • <SirvGallery> - a list of mixed assets, either as separate components or one combined Sirv Media Viewer.

Renders a responsive Sirv image with an auto-generated srcset across sensible default widths (320, 480, 640, 768, 1024, 1280, 1600 px).

Accepts either a stored value or an explicit alias + path.

<SirvImage
path="/products/shoe.jpg"
width={800}
height={600}
alt="Product shoe"
sizes="(min-width: 1024px) 50vw, 100vw"
/>

Set priority on above-the-fold hero images to eager-load them, or switch to lazyMode="sirvjs" for sirv.js DPR-aware loading.

Delivers a Sirv video with a poster frame derived from the source (or an explicit poster value of your choosing):

<SirvVideo
path="/clips/intro.mp4"
width={1280}
controls
muted
loop
/>

Renders a 360° spin in a sirv.js container. sirv.js is auto-loaded the first time a spin (or view, or viewer) mounts and reused for every other instance on the page:

<SirvSpin path="/spins/watch.spin" width={500} height={500} />

Renders a Sirv composite “view” - a layered scene driven by sirv.js:

<SirvView path="/views/scene.view" width={800} height={450} />

Renders a 3D model (.glb) in a sirv.js container - the same way as a spin or view, with sirv.js auto-loaded on first use:

<SirvModel path="/models/chair.glb" width={600} height={600} />

A polymorphic renderer that picks the right component based on the value’s _type field. Ideal for a CMS field whose type can vary between image, video, spin, view and 3D model:

<SirvMedia
value={{
_type: 'sirv.image',
asset: { sirvAlias: 'demo.sirv.com', sirvPath: '/products/shoe.jpg' },
alt: 'Hero',
}}
width={800}
/>

Renders a list of mixed Sirv assets in one of two layouts:

  • separate (default) - each asset becomes its own component in a responsive grid.
  • viewer - all assets are combined into ONE Sirv Media Viewer container (a single .Sirv element with a data-src child per asset); images become zoomable (data-type="zoom").
// Separate components in a responsive grid:
<SirvGallery items={items} layout="separate" itemWidth={300} />
// One combined Sirv Media Viewer:
<SirvGallery items={items} layout="viewer" width={640} height={480} />

Here’s what the combined viewer layout looks like with mixed assets (zoomable images, 360 spin and autoplaying videos):

The <SirvImage> component accepts a transformations prop that exposes the full set of Sirv dynamic-imaging parameters, such as crop (with face / point-of-interest / trim detection).

It also covers rotate, flip, blur, sharpen, grayscale, brightness, contrast, saturation, hue, colortone, saved profiles, page (for PDFs), and more.

Face-cropped, slightly sharpened, grayscale avatar:

<SirvImage
path="/people/jane.jpg"
width={400}
height={400}
alt="Jane"
transformations={{
crop: { width: 400, height: 400, type: 'face' },
grayscale: true,
sharpen: 30,
}}
/>

Apply a saved Sirv profile to any image:

<SirvImage
path="/products/shoe.jpg"
width={1200}
alt="Shoe"
transformations={{ profile: 'Hero' }}
/>

Generate a cheap, blurred low-quality placeholder (LQIP):

<SirvImage
path="/products/shoe.jpg"
width={10}
alt=""
transformations={{ blur: 20 }}
/>

Precedence: the transformations prop wins over any value.transformations coming from your CMS, which in turn wins over provider defaults.

Anything not modelled in the type goes through transformations.extras and is emitted verbatim as a query parameter.

Pass sirv.js spin options via the options prop. Each camelCase key becomes a data-<kebab-case> attribute on the spin container:

<SirvSpin
path="/spins/watch.spin"
width={500}
height={500}
options={{
autospin: 'always',
autospinSpeed: 200,
spinDirection: 'cw',
hint: 'once',
bottomBar: 'hide',
fullscreenZoom: true,
}}
/>

Use options.extras for any spin attribute not modelled directly in the type.

When <SirvGallery> is in layout="viewer" mode, the viewer prop maps the common Sirv Media Viewer knobs onto data-* attributes on the container:

<SirvGallery
items={items}
layout="viewer"
width={800}
height={600}
viewer={{
thumbnails: 'bottom',
thumbnailsType: 'image',
autoplay: 4000,
autoplayPauseOnHover: true,
slideDuration: 600,
zoom: true,
fullscreen: true,
arrows: true,
loop: true,
}}
/>

Anything else goes through viewer.extras.

Use Sirv as the optimizer behind next/image. Re-export the loader, then point your next.config at it:

sirv-loader.ts
export { sirvLoader as default } from '@sirv/react/next';
next.config.mjs
export default {
images: { loader: 'custom', loaderFile: './sirv-loader.ts' },
};

SirvMediaLike is structural, so values from any source that match the shape work directly with <SirvMedia>.

If you store Sirv assets with the official Sirv Sanity plugin (sirvMedia field), convert them with the bundled fromSanityMedia() adapter:

import { SirvMedia, fromSanityMedia } from '@sirv/react';
<SirvMedia value={fromSanityMedia(post.heroMedia)} width={640} />

<SirvProvider alias="..."> goes near your app root. Every nested component inherits the alias from context, so you never pass it again.

A component’s own alias prop is just an optional override for a one-off asset from another account.

<SirvProvider alias="my-account.sirv.com" quality={85} lazyMode="native">
{/* every <SirvImage>, <SirvVideo>, <SirvSpin>, <SirvView>, <SirvMedia> and
<SirvGallery> inside here inherits the alias and the defaults. */}
</SirvProvider>

You can skip the provider entirely and pass alias per component, but that’s the verbose path.

Does @sirv/react work with React Server Components?

Yes. The package ships with a 'use client' boundary so the components drop straight into React Server Component apps (App Router on Next.js 13+). The components render on the client; the URL helpers are usable from server code too.

Do I need to load sirv.js manually?

No. The package loads sirv.js automatically the first time a spin, view or media-viewer gallery mounts, and reuses that single script for every other instance on the page. Plain images use the native <img> element with srcset and don't need sirv.js at all.

Which React versions are supported?

React 18 and 19. They're listed as peer dependencies, so the package adds no extra runtime weight beyond what your app already includes.

Can I use this with next/image instead of <SirvImage>?

Yes. Re-export sirvLoader from @sirv/react/next and configure it in next.config as a custom loader. next/image will then route every URL through Sirv for optimization and CDN delivery. See the "Next.js image loader" section above.

How do I apply dynamic imaging parameters that aren't in the TypeScript type?

Use the extras escape hatch on transformations (for <SirvImage>), on options (for <SirvSpin>), or on viewer (for <SirvGallery>). Keys are emitted verbatim as Sirv query parameters or as data-<kebab-case> attributes respectively.

  • v0.2.2 (June 12, 2026)
    • Documentation release: README and generated docs updated to cover <SirvModel> for .glb 3D models. No code changes.
  • v0.2.1 (June 12, 2026)
    • New <SirvModel> component renders .glb 3D models via sirv.js.
    • <SirvMedia> now dispatches to <SirvModel> when the value’s _type is sirv.model.
    • Exported SirvModelProps and SirvModelLike types from the package root.
  • v0.2.0 (June 12, 2026)
    • New transformations prop on <SirvImage> exposes the full set of Sirv dynamic-imaging parameters (crop, rotate, blur, grayscale, profile, page, …).
    • New options prop on <SirvSpin> for sirv.js spin behaviour (autospin, hint, bottomBar, fullscreenZoom, …).
    • New viewer prop on <SirvGallery layout="viewer"> for Sirv Media Viewer settings (thumbnails, autoplay, slideDuration, zoom, fullscreen, arrows, loop).
    • <SirvMedia> forwards transformations and spinOptions to the underlying component.
    • Exported Transformations, SirvSpinOptions and SirvViewerOptions from the package root.
All versions
  • v0.1.1 (June 11, 2026)
    • Refreshed package description and documentation.
  • v0.1.0 (June 10, 2026)
    • First release. Six standalone React components for Sirv assets: <SirvImage>, <SirvVideo>, <SirvSpin>, <SirvView>, <SirvMedia> and <SirvGallery>.
    • Responsive srcset + native lazy loading, or sirv.js DPR-aware mode.
    • sirv.js auto-loaded only when a spin, view or viewer needs it.
    • Zero runtime dependencies; React 18 / 19 as peers.
    • ESM + CJS + TypeScript types, with a 'use client' boundary for React Server Component apps.
    • sirvLoader export for use as a custom next/image loader.
    • fromSanityMedia() adapter for the Sirv Sanity plugin’s stored values.
Back to top