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

25 lines
559 B
TypeScript

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