Skip to Content

Installation and rendering

Install the Rixl React SDK in a SPA, Next.js, or TanStack Start and connect before loading media.

Requirements

Use React 18 or later for the examples and player hooks. Your app supplies React and React DOM. The SDK includes Core, Lit, HLS support, TypeScript declarations, and player styles.

npm install @rixl/media-react

No global SDK stylesheet or Tailwind CSS configuration is needed.

React SPA

Initialize the connection in your entry file before mounting media:

src/main.tsx
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 already authenticates the shared @rixl/sdk client, reuse that connection.

Next.js App Router and TanStack Start

Use the same React package. The UI entries and hooks preserve "use client"; /core and the root barrel remain outside that client boundary. No separate Rixl framework package or ssr.noExternal setting is needed.

For a page that connects in the browser, use a client component that waits before mounting media:

components/MediaExample.tsx
"use client";

import {useEffect, useState} from "react";
import {connect} from "@rixl/media-react/core";
import {Video} from "@rixl/media-react/video";

export default function MediaExample() {
  const [ready, setReady] = useState(false);
  const [error, setError] = useState("");

  useEffect(() => {
    let active = true;
    connect({baseUrl: "https://api.rixl.com", apiKey: "YOUR_PUBLIC_API_KEY"})
      .then(() => {
        if (active) setReady(true);
      })
      .catch(() => {
        if (active) setError("Unable to connect to Rixl.");
      });
    return () => {
      active = false;
    };
  }, []);

  if (error) return <p role="alert">{error}</p>;
  if (!ready) return <p role="status">Loading media…</p>;
  return <Video id="YOUR_VIDEO_ID" muted style={{display: "block", aspectRatio: "16 / 9"}} />;
}

Import this component from your Next.js page or render it in a TanStack Start route. In an app with several media sections, initialize the shared browser connection at their common boundary instead of reconnecting per player.

This example renders its loading state on the server. When media components themselves are server-rendered, React produces custom-element hosts and supplied children. The internal image, video, controls, and feed items render in the browser. Put essential page text and metadata in your application's server HTML.

Keep server credentials in server code. Callbacks, refs, and player hooks belong inside client components.

Styling and imports

Give images and videos a height or aspect ratio and feeds a height. className and style configure the host layout; internal player styles live in shadow DOM.

import {Image} from "@rixl/media-react/image";
import {Video, VideoPlayer} from "@rixl/media-react/video";
import {Feed} from "@rixl/media-react/feed";
import {usePlayback, usePlayerProgress} from "@rixl/media-react";

An image-only subpath import excludes video, feed, and HLS code. Remove obsolete imports of @rixl/media-react/style.css or /dev when migrating.

Troubleshooting

  • Media is blank: await the browser connection, provide a valid media ID, and set host dimensions.
  • Autoplay is blocked: request muted autoplay and account for the browser's playback policy.
  • A hook cannot find its player: render it inside Video or a shared VideoPlayer scope.
  • Host classes do not change controls: configure the player through props; internal controls are inside shadow DOM.