nteract elements

Media Provider

Shared configuration context for MIME type rendering

Provides shared rendering configuration (custom renderers, priority) to all nested MediaRouter instances via React context. Configure MIME type rendering once at the top of the tree instead of passing props to every MediaRouter.

Installation

npx shadcn@latest add @nteract/media-provider

New to @nteract? pnpm dlx shadcn@latest registry add @nteract

MediaProvider is included automatically when you install MediaRouter.

Usage

Custom Renderers

Register renderers for MIME types not handled by built-in components. All nested MediaRouter instances inherit them:

import { MediaProvider } from "@/components/outputs/media-provider"
import { PlotlyChart } from "./plotly-chart"

<MediaProvider
  renderers={{
    "application/vnd.plotly.v1+json": ({ data }) => (
      <PlotlyChart data={data} />
    ),
  }}
>
  {/* All outputs can now render Plotly */}
  {cells.map(cell => (
    <OutputArea key={cell.id} outputs={cell.outputs} />
  ))}
</MediaProvider>

With Widgets

Bridge the widget system into the media pipeline so widget-type outputs render automatically:

import { MediaProvider } from "@/components/outputs/media-provider"
import { WidgetStoreProvider } from "@/components/widgets/widget-store-context"
import { WidgetView } from "@/components/widgets/widget-view"
import "@/components/widgets/controls"

<WidgetStoreProvider sendMessage={sendToKernel}>
  <MediaProvider
    renderers={{
      "application/vnd.jupyter.widget-view+json": ({ data }) => {
        const { model_id } = data as { model_id: string };
        return <WidgetView modelId={model_id} />;
      },
    }}
  >
    <OutputArea outputs={cell.outputs} />
  </MediaProvider>
</WidgetStoreProvider>

Nesting

Inner providers merge renderers with outer providers (inner wins for the same MIME type) and override priority entirely:

<MediaProvider renderers={{ "application/vnd.vegalite.v5+json": VegaLite }}>
  {/* Inner adds Plotly without losing the outer VegaLite renderer */}
  <MediaProvider renderers={{ "application/vnd.plotly.v1+json": Plotly }}>
    <OutputArea outputs={outputs} />
  </MediaProvider>
</MediaProvider>

Props

PropTypeDefaultDescription
renderersRecord<string, CustomRenderer>{}Custom MIME type renderers, merged with parent provider
priorityreadonly string[]DEFAULT_PRIORITYMIME type priority order, overrides parent
childrenReactNodeChild components

How It Works

MediaRouter resolves configuration with this fallback chain:

  1. Direct props (highest priority) — props passed directly to <MediaRouter>
  2. MediaProvider context — inherited from the nearest provider
  3. Built-in defaultsDEFAULT_PRIORITY, empty renderers

Without a MediaProvider in the tree, MediaRouter behaves exactly as before.

On this page