packages/synapse-interface/utils/hooks/useCloseOnOutsideClick.ts
import { useEffect } from 'react'
const useCloseOnOutsideClick = (ref, onClose) => {
const handleClickOutside = (event) => {
if (ref.current && !ref.current.contains(event.target)) {
onClose()
}
}
useEffect(() => {
document.addEventListener('mousedown', handleClickOutside)
return () => {
document.removeEventListener('mousedown', handleClickOutside)
}
}, [ref, onClose])
}
export default useCloseOnOutsideClick