24 lines
509 B
TypeScript
24 lines
509 B
TypeScript
"use client"
|
|
|
|
import { useParams } from "next/navigation"
|
|
import { useEffect, useState } from "react"
|
|
|
|
function getHash() {
|
|
return typeof window !== "undefined" ? window.location.hash : undefined
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
export default useHash
|