Created Layout & Responsive Header Component

This commit is contained in:
aftabrehan
2024-02-01 20:28:42 +05:00
parent 9ac97c7f9a
commit bc7cad7e3b
21 changed files with 413 additions and 30 deletions

16
hooks/useClickOutside.ts Normal file
View 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])
}