UNPKG

@figliolia/react-hooks

Version:

A small collection of simple React Hooks you're probably rewriting on a regular basis

12 lines (10 loc) 310 B
import { useEffect, useRef } from "react"; import type { Callback } from "Types"; export const useUnmount = (onUnmount: Callback) => { const callback = useRef<Callback>(onUnmount); callback.current = onUnmount; useEffect(() => { const { current: fn } = callback; return () => fn(); }, []); };