Skip to content
FrameworkStyle

useOptionalContainer

Hook to access a Player container when one is available

Import

import { useOptionalContainer } from "@videojs/react";

Usage

Use the optional hook when a component can work both inside and outside Player.

function ContainerAwareStatus() {
  const container = useOptionalContainer();

  return <output>{container ? "Player container ready" : "No container"}</output>;
}

It returns null outside Player, before its container mounts, or when the player has no registered container. Use useContainer when a missing Player should be treated as an error.

API Reference

Return Value

object | null