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(() => {
11 setResult([false, false]);
12 } else if (!isOpen && isOpenPrevious) {
13 setResult([true, false]);
15 }, [isOpen, isOpenPrevious]);
17 const setIsClosed = () => setResult([false, true]);
19 return [isClosed, isClosing, setIsClosed];
22 export default useIsClosing;