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

View File

@@ -0,0 +1,19 @@
import { useRef, useEffect, useState } from 'react'
import { createPortal } from 'react-dom'
interface modalPortal {
children: React.ReactNode
selector?: string
}
export const ModalPortal = ({ children, selector = 'modal' }: modalPortal) => {
const ref = useRef<HTMLDivElement | null>(null)
const [mounted, setMounted] = useState(false)
useEffect(() => {
ref.current = document.querySelector(selector)
setMounted(true)
}, [selector])
return mounted && ref.current ? createPortal(children, ref.current) : null
}