rsuite
Version:
A suite of react components
15 lines (14 loc) • 402 B
JavaScript
'use client';
import useUpdatedRef from "./useUpdatedRef.js";
import { useEffect } from 'react';
/**
* Attach a callback that fires when a component unmounts
*
* @param fn Handler to run when the component unmounts
* @category effects
*/
export function useWillUnmount(fn) {
const onUnmount = useUpdatedRef(fn);
useEffect(() => () => onUnmount.current(), []);
}
export default useWillUnmount;