Files
web/hooks/useHash.tsx
2024-08-12 10:26:02 +02:00

23 lines
482 B
TypeScript

"use client"
import { useParams } from "next/navigation"
import { useEffect, useState } from "react"
const getHash = () =>
typeof window !== "undefined" ? window.location.hash : undefined
const useHash = () => {
const [isClient, setIsClient] = useState(false)
const [hash, setHash] = useState(getHash())
const params = useParams()
useEffect(() => {
setIsClient(true)
setHash(getHash())
}, [params])
return isClient ? hash : null
}
export default useHash