Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / components / hooks / useIsClosing.ts
blobf347cb9828d6ef63cb641c248c6899f912e56840
1 import { useLayoutEffect, useState } from 'react';
3 import usePrevious from '@proton/hooks/usePrevious';
5 const useIsClosing = (isOpen = false): [boolean, boolean, () => void] => {
6     const [[isClosed, isClosing], setResult] = useState(() => [false, !isOpen]);
7     const isOpenPrevious = usePrevious(isOpen);
9     useLayoutEffect(() => {
10         if (isOpen) {
11             setResult([false, false]);
12         } else if (!isOpen && isOpenPrevious) {
13             setResult([true, false]);
14         }
15     }, [isOpen, isOpenPrevious]);
17     const setIsClosed = () => setResult([false, true]);
19     return [isClosed, isClosing, setIsClosed];
22 export default useIsClosing;