Player.Provider to the hooks and components beneath it. Most applications use the typed API returned by createPlayer — these primitives are for building custom player infrastructure or integrating with the player at a lower level.
Container
The player root element. Wraps media content and controls, and attaches the player store to the DOM when a media element is registered. Exported directly from@videojs/react and included in the result of createPlayer.
Container forwards a ref to the underlying HTMLDivElement and passes all standard HTMLDivElement attributes through.
ContainerProps
The media element and controls to render inside the container.
All standard
div attributes — className, style, id, onClick, etc.Forwarded ref to the underlying
div element.How Container works
Internally,Container calls store.attach({ media, container }) when both the store and a registered media element are available. This wires up container-level features like fullscreen. The effect re-runs if the media element changes.
usePlayerContext()
Returns the rawPlayerContextValue from the nearest Player.Provider. Throws if called outside a provider.
Use this when you need simultaneous access to the store, the current media element, and the media setter — for example, when building a custom container or provider wrapper.
Return value
The player store instance. Use
usePlayer or useStore to subscribe to state from the store.The currently registered media element (
HTMLVideoElement or HTMLAudioElement), or null if none has mounted yet.The React state setter for the media element. Pass this to
useMediaRegistration consumers. Calling it with an element registers that element as the active media; calling it with null unregisters.useMediaRegistration()
Returns thesetMedia setter from the player context, or undefined if called outside a provider. Use this in custom media components to register an HTMLMediaElement with the player.
Return value
The media registration setter, or
undefined if called outside a Player.Provider. Always check for undefined before calling (e.g., setMedia?.(element)).PlayerContextValue type
The shape of the value provided byPlayer.Provider via React context.
The player store instance created by
createPlayer when Provider mounts.The registered
HTMLMediaElement, or null if none has been registered.Setter for registering or unregistering the active media element.
Typical usage patterns
Building a custom skin
When you build a custom skin component, useContainer directly rather than through createPlayer. This lets you import once and reuse across multiple player instances:
Custom provider wrapper
WrapPlayer.Provider with additional context using usePlayerContext: