feat(SW-441): Implemented useScrollSpy hook

This commit is contained in:
Erik Tiekstra
2024-10-01 13:01:21 +02:00
parent a567190080
commit 275d85f482
10 changed files with 138 additions and 28 deletions

View File

@@ -4,10 +4,13 @@ import { useParams } from "next/navigation"
import { useEffect, useState } from "react"
function getHash() {
return typeof window !== "undefined" ? window.location.hash : undefined
if (typeof window === "undefined" || !window.location.hash) {
return undefined
}
return window.location.hash.split("#")[1]
}
function useHash() {
export default function useHash() {
const [isClient, setIsClient] = useState(false)
const [hash, setHash] = useState(getHash())
const params = useParams()
@@ -19,5 +22,3 @@ function useHash() {
return isClient ? hash : null
}
export default useHash