Skip to Content

Media React

React video player, images, and infinite media feeds for Rixl, with player hooks and Next.js and TanStack Start support.

A React video player, image components, and infinite media feeds for Rixl. Use @rixl/media-react in a normal React SPA, Next.js, or TanStack Start, with TypeScript props and hooks for custom player controls.

What you get

  • Adaptive HLS video playback with controls, captions, quality selection, fullscreen, and picture-in-picture.
  • Images with lazy loading and ThumbHash placeholders when available.
  • Vertical media feeds with pagination, looping, and automatic advancement.
  • Scoped hooks for playback, seeking, volume, audio tracks, subtitles, and player UI.
  • Included player styles, with no Tailwind CSS setup or global SDK stylesheet.

Install

npm install @rixl/media-react

Use React 18 or later for the examples and player hooks. Core, Lit, and the media dependencies are installed automatically; your app supplies React and React DOM.

Quick start: React SPA

Connect before mounting components that request media. In a Vite or other client-rendered React app, initialize the SDK in your entry file:

import {createRoot} from "react-dom/client";
import {connect} from "@rixl/media-react/core";
import {Video} from "@rixl/media-react/video";

async function main() {
  await connect({
    baseUrl: "https://api.rixl.com",
    apiKey: "YOUR_PUBLIC_API_KEY",
  });

  const container = document.getElementById("root");
  if (!container) throw new Error("Missing #root element");

  createRoot(container).render(<Video id="YOUR_VIDEO_ID" muted style={{display: "block", width: "100%", aspectRatio: "16 / 9"}} />);
}

main().catch(console.error);

Use credentials intended for browser access. If your host application already authenticates the shared @rixl/sdk client, reuse that connection.

Images and feeds

import {Image} from "@rixl/media-react/image";
import {Feed} from "@rixl/media-react/feed";

export function MediaGallery() {
  return (
    <>
      <Image id="YOUR_IMAGE_ID" alt="Mountain lake at sunrise" style={{display: "block", width: "100%", aspectRatio: "16 / 9"}} />
      <Feed feedId="YOUR_FEED_ID" muted style={{display: "block", height: "36rem"}} />
    </>
  );
}

Render this after connecting. Production components load media by id or feedId through the SDK.

Custom player controls

Put custom controls inside <Video>, or use <VideoPlayer> to share a player with sibling controls. Hooks resolve the player from React context.

import {Video, VideoPlayer} from "@rixl/media-react/video";
import {usePlayback} from "@rixl/media-react";

function PlayButton() {
  const {paused, togglePlay} = usePlayback();
  return (
    <button type="button" onClick={() => void togglePlay()}>
      {paused ? "Play" : "Pause"}
    </button>
  );
}

export function CustomPlayer() {
  return (
    <VideoPlayer>
      <Video id="YOUR_VIDEO_ID" theme="hideUI" style={{display: "block", aspectRatio: "16 / 9"}} />
      <PlayButton />
    </VideoPlayer>
  );
}
HookPurpose
usePlayback()Play, pause, playback rate, and loading state
useMediaSettings()Mute and volume for the current player
usePlayerProgress()Timeline state and seeking
usePlayerTracks()Audio and subtitle selection
usePlayerUI()Controls visibility, fullscreen, and picture-in-picture
useGlobalPlayerSettings()Shared preferences across players
useProgressBar({video})Seeking interactions for a raw browser video element

Player-scoped hooks take no player ID. Keep one <Video> in each <VideoPlayer> scope. useGlobalPlayerSettings and useProgressBar do not require a player scope.

Callbacks such as onPausedChange, onLoadingChange, and Feed's onMuteChange receive booleans. onRixlAnalytics receives a custom event; read its payload through event.detail.event. Refs point to the underlying Lit element.

Next.js and TanStack Start

The same package supports client rendering, server rendering, and prerendering. No separate Next.js or TanStack adapter is needed.

  • React renders custom-element hosts and your light-DOM children on the server.
  • Lit renders the image, video, controls, and feed content in the browser. Those contents are absent from the initial server HTML.
  • UI entries and hooks preserve "use client". The root barrel and /core remain outside that client boundary.
  • Connect the shared client in the browser before mounting media that fetches by ID. Keep server credentials in server code.

For a Next.js App Router client boundary, initialize the connection in an effect and mount media after it resolves. TanStack Start can use the same pattern inside a route. Server rendering is optional: React SPAs use the quick start above unchanged.

See the installation and rendering guide for setup examples. Include essential page text and metadata in your application's server HTML when you need them there.

Styling and imports

Use className or style to size and position the host. Give images and videos an explicit height or aspect ratio, and feeds a height. Internal player styles live in shadow DOM; host classes do not select internal controls.

ImportExports
@rixl/media-react/imageImage, ImageProps
@rixl/media-react/videoVideo, VideoPlayer, and their props
@rixl/media-react/feedFeed, FeedProps
@rixl/media-react/coreHeadless APIs, stores, utilities, and types
@rixl/media-reactComponents, hooks, and Core exports

An image-only subpath import excludes video, feed, and HLS code. The obsolete @rixl/media-react/style.css and /dev entries are not exported.

Component guides