fix(SW-441): fixes after PR
This commit is contained in:
@@ -3,22 +3,26 @@
|
||||
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 [hash, setHash] = useState<string | undefined>(undefined)
|
||||
const params = useParams()
|
||||
|
||||
useEffect(() => {
|
||||
setIsClient(true)
|
||||
setHash(getHash())
|
||||
}, [params, setHash, setIsClient])
|
||||
const updateHash = () => {
|
||||
const newHash = window.location.hash
|
||||
? window.location.hash.slice(1)
|
||||
: undefined
|
||||
setHash(newHash)
|
||||
}
|
||||
|
||||
return isClient ? hash : null
|
||||
updateHash()
|
||||
|
||||
window.addEventListener("hashchange", updateHash)
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("hashchange", updateHash)
|
||||
}
|
||||
}, [params])
|
||||
|
||||
return hash
|
||||
}
|
||||
|
||||
@@ -46,12 +46,9 @@ export default function useScrollSpy(
|
||||
const observer = new IntersectionObserver(handleIntersection, mergedOptions)
|
||||
const elements = sectionIds
|
||||
.map((id) => document.getElementById(id))
|
||||
.filter(Boolean)
|
||||
.filter((el): el is HTMLElement => !!el)
|
||||
|
||||
elements.forEach((element) => {
|
||||
if (!element) {
|
||||
return
|
||||
}
|
||||
observer.observe(element)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user