useDestroy
Hook that destroys an imperative instance after a real React unmount
Import
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.
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
Parameters
| Parameter | Type | Default | Details |
|---|---|---|---|
instance* | { destroy(): void } | — | |
| |||
setup | function | — | |
| |||
teardown | function | — | |
| |||
Return Value
void