useClickOutside

Handles the event of clicking outside of the wrapped component.

Usage

import React, { useState, useRef } from "react";
import useClickOutside from 'funda-ui/Utils/useClickOutsidex';
 
const App = () => {
 
    const [show, setShow] = useState<boolean>(false);
    const dropdownRef = useRef<HTMLDivElement>(null);
 
    useClickOutside({
        enabled: show && dropdownRef.current,
        isOutside: (event: any) => {
            return event.target.closest(`.test__wrapper`) === null && event.target.closest(`.test__wrapper2`) === null;
        },
        handle: (event: any) => {
            // do something
            //...
        },
        spyElement: document
    }, [show, dropdownRef]);
};