This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useRef } from 'react'; | |
| const useClickOutside = (callback: () => void) => { | |
| const ref = useRef<HTMLElement>(null); | |
| useEffect(() => { | |
| const handleClickOutside = (event: MouseEvent) => { | |
| // If the ref exists and the clicked element is not inside the ref's element | |
| if (ref.current && !ref.current.contains(event.target as Node)) { | |
| callback(); // Execute the provided callback function |