📡 Detect clicks outside of elements and close components in reverse order.
npm i use-lifo-click-outside
import { useLifoClickOutside } from 'use-lifo-click-outside';
useLifoClickOutside(ref, onClose);
<Portal>
<Modal ref={ref}>
...
</Modal>
</Portal>