# useDestroy

Hook that destroys an imperative instance after a real React unmount

## Import

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

## Usage

Pass an object with a `destroy()` method. Optional setup and teardown callbacks run around the instance’s mounted lifetime.

```tsx
type Destroyable = { destroy(): void };

function ManagedInstance({ instance }: { instance: Destroyable }) {
  useDestroy(instance);

  return null;
}
```

Destruction is deferred to a macrotask so React StrictMode’s simulated unmount and remount can cancel it. A real unmount runs teardown before `destroy()`.

## API Reference

`useDestroy(instance, setup?, teardown?): void`

### Parameters

| Parameter | Type | Default | Description |
| --- | --- | --- | --- |
| `instance` (required) | `{ destroy(): void }` | — | Object with a `destroy()` method. |
| `setup` | `(() => void)` | — | Optional setup called on first mount. Skipped on StrictMode re-mount since the previous setup was never torn down. |
| `teardown` | `(() => void)` | — | Optional teardown called right before `destroy()` on real unmount. Skipped on StrictMode simulated unmount. |

### Return Value

`void`

---

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