Docs
useUnmount

Run a function when a component unmounts, ensuring cleanups or final actions are handled effectively.

Installation

pnpm dlx shadcn@latest add https://usekit.kiron.dev/k/use-unmount

Usage

"use client"
 
import { useUnmount } from "@/hooks/use-unmount"
 
export default function Component() {
  useUnmount(() => {
    // Cleanup logic here
  })
 
  return <div>Hello world</div>
}

API Reference

Parameters

NameTypeDescriptionDefault ValueOptional
Function() => voidThe cleanup function to be executed on unmount.() => undefinedNo

Return Values

TypeDescription
voidA function that runs the cleanup function when the component unmounts.