# Sirv React components

![React logo](https://sirv.sirv.com/website/react-logo.svg)

Drop responsive Sirv images, videos, [360 spins](/help/spin/getting-started/how-spin-files-are-created/), Sirv “views”, [3D models](/help/sirv-media-viewer/media-types/3d-model/) (.glb) and combined media-viewer galleries straight into any React app with the official `@sirv/react` package.

Using an AI coding agent?

Install the [`image-optimization`](https://www.skills.sh/sirv/image-optimization-skill/image-optimization) skill, and your agent can set up Sirv images in your project. Ask in plain words, such as “Serve our product images from Sirv and make them load faster.” [See all 8 skills](/help/rest-api/sirv-skills-for-ai-agents/)

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.

## Installation

1.  Install the package with your favourite package manager:
    
    ```bash
    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.
    
    ```tsx
    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](/help/dynamic-imaging/format-quality/format/) negotiation - no extra wiring required.

## Components

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.

### SirvImage

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`.

```tsx
<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.

### SirvVideo

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

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

### SirvSpin

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:

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

### SirvView

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

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

### SirvModel

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:

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

### SirvMedia

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:

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

### SirvGallery

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"`).

```tsx
// 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):

## Dynamic imaging

The `<SirvImage>` component accepts a `transformations` prop that exposes the full set of [Sirv dynamic-imaging parameters](/help/dynamic-imaging/), 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:

```tsx
<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:

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

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

```tsx
<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.

## 360 spin options

Pass [sirv.js spin options](/help/sirv-media-viewer/media-types/360-spin/#options) via the `options` prop. Each camelCase key becomes a `data-<kebab-case>` attribute on the spin container:

```tsx
<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.

## Sirv Media Viewer options

When `<SirvGallery>` is in `layout="viewer"` mode, the `viewer` prop maps the common [Sirv Media Viewer](/help/sirv-media-viewer/) knobs onto `data-*` attributes on the container:

```tsx
<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`.

## Next.js image loader

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

```ts
export { sirvLoader as default } from '@sirv/react/next';
```

```js
export default {
  images: { loader: 'custom', loaderFile: './sirv-loader.ts' },
};
```

## Using stored CMS values

`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](/help/integrations/cms-website-builders/sanity-studio-plugin/) (`sirvMedia` field), convert them with the bundled `fromSanityMedia()` adapter:

```tsx
import { SirvMedia, fromSanityMedia } from '@sirv/react';

<SirvMedia value={fromSanityMedia(post.heroMedia)} width={640} />
```

## Set your alias once

`<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.

```tsx
<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.

## Common questions

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.

## Changelog

-   **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.
