From 5284c8a4bee52fde072d352c2d6ec55854b09e04 Mon Sep 17 00:00:00 2001 From: Ward Oosterlijnck Date: Sun, 31 Mar 2019 20:01:31 +1100 Subject: [PATCH] Refactor useUnmount --- src/useUnmount.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/useUnmount.ts b/src/useUnmount.ts index 69df3b5f..74977cc1 100644 --- a/src/useUnmount.ts +++ b/src/useUnmount.ts @@ -1,9 +1,7 @@ -import {useEffect} from 'react'; +import useEffectOnce from './useEffectOnce' -const useUnmount = (unmount) => { - useEffect(() => () => { - if (unmount) unmount(); - }, []); +const useUnmount = (fn: () => void | undefined) => { + useEffectOnce(() => fn); }; export default useUnmount;