Skip to content
FrameworkStyle

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

ParameterTypeDefaultDetails
instance*{ destroy(): void }
setupfunction
teardownfunction

Return Value

void