Created Layout & Responsive Header Component
This commit is contained in:
16
hooks/useClickOutside.ts
Normal file
16
hooks/useClickOutside.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { useEffect } from 'react'
|
||||
|
||||
interface funcProps {
|
||||
onClick: () => void
|
||||
ref: { current: HTMLDivElement } | { current: null }
|
||||
}
|
||||
|
||||
export const useClickOutside = ({ onClick, ref }: funcProps) => {
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (e: any) =>
|
||||
ref.current && !ref.current.contains(e.target) && onClick()
|
||||
|
||||
document.addEventListener('mousedown', handleClickOutside)
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside)
|
||||
}, [onClick, ref])
|
||||
}
|
||||
Reference in New Issue
Block a user