{"version":3,"file":"useBeforeUnmount.cjs","names":[],"sources":["../../src/useBeforeUnmount/useBeforeUnmount.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\n/**\n * Runs the latest callback when the component unmounts.\n *\n * @param fn - Cleanup callback.\n *\n * @example\n * ```tsx\n * useBeforeUnmount(() => {\n *   subscription.close();\n * });\n * ```\n */\nexport const useBeforeUnmount = (fn: () => void): void => {\n  const fnRef = useRef(fn);\n  fnRef.current = fn;\n\n  useEffect(() => () => fnRef.current(), []);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAa,oBAAoB,OAAyB;CACxD,MAAM,SAAA,GAAA,MAAA,OAAA,CAAe,EAAE;CACvB,MAAM,UAAU;CAEhB,CAAA,GAAA,MAAA,UAAA,aAAsB,MAAM,QAAQ,GAAG,CAAC,CAAC;AAC3C"}