# useOptionalContainer

Hook to access a Player container when one is available

## Import

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

## Usage

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

```tsx
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

`useOptionalContainer(): MediaContainer | null`

### Return Value

`MediaContainer | null`

---

React documentation: https://videojs.org/docs/framework/react/llms.txt
All documentation: https://videojs.org/llms.txt
