feat(SW-441): Implemented useScrollSpy hook
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user