1 | import useUpdatedRef from './useUpdatedRef';
|
2 | import { useEffect } from 'react';
|
3 | /**
|
4 | * Attach a callback that fires when a component unmounts
|
5 | *
|
6 | * @param fn Handler to run when the component unmounts
|
7 | * @category effects
|
8 | */
|
9 |
|
10 | export default function useWillUnmount(fn) {
|
11 | var onUnmount = useUpdatedRef(fn);
|
12 | useEffect(function () {
|
13 | return function () {
|
14 | return onUnmount.current();
|
15 | };
|
16 | }, []);
|
17 | } |
\ | No newline at end of file |