25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

useWillUnmount.js 412 B

3 년 전
1234567891011121314151617
  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. export default function useWillUnmount(fn) {
  10. var onUnmount = useUpdatedRef(fn);
  11. useEffect(function () {
  12. return function () {
  13. return onUnmount.current();
  14. };
  15. }, []);
  16. }