UNPKG

@supunlakmal/hooks

Version:

A collection of reusable React hooks

17 lines 552 B
import { useEffect } from 'react'; import { useSyncedRef } from '../performance-optimization/useSyncedRef'; /** * Run effect only when component is unmounted. * * @param effect Effector to run on unmount */ export const useUnmountEffect = (effect) => { const effectRef = useSyncedRef(effect); useEffect(() => () => { // eslint-disable-next-line @typescript-eslint/no-unsafe-call effectRef.current(); }, // eslint-disable-next-line react-hooks/exhaustive-deps []); }; //# sourceMappingURL=useUnmountEffect.js.map