Rehooks

useUnmount

Executes a callback function when the component unmounts.

useUnmount

Installation

npx rehooks-cli@latest add useUnmount

Usage

Component.tsx
import { useUnmount } from "~/hooks/useUnmount";
 
function Component() {
  useUnmount(() => {
    // Do something when the component is unmounted
  });
 
  return <div>Component</div>;
}

API

useUnmount

useUnmount.ts
function useUnmount(fn: () => void): void;

Executes a callback function when the component unmounts.

Parameters

NameTypeDescription
fn() => voidThe callback function to be executed on unmount.

On this page