25 lines
559 B
TypeScript
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
|
|
}
|