mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-04 23:44:11 +02:00
25 lines
627 B
TypeScript
25 lines
627 B
TypeScript
import { useState } from "react"
|
|
|
|
export const useLockBodyScroll = () => {
|
|
const documentGlobal = typeof document !== "undefined" && document
|
|
const [locked, setLocked] = useState<boolean>(false)
|
|
|
|
function lock() {
|
|
setLocked(true)
|
|
}
|
|
|
|
function unlock() {
|
|
setLocked(false)
|
|
}
|
|
|
|
const body = documentGlobal && document.querySelector("body")
|
|
const gatsbyNode =
|
|
documentGlobal && document.querySelector<HTMLDivElement>("#___gatsby")
|
|
if (body && gatsbyNode) {
|
|
body.style.overflow = locked ? "hidden" : ""
|
|
gatsbyNode.style.overflowY = locked ? "scroll" : ""
|
|
}
|
|
|
|
return { locked, lock, unlock }
|
|
}
|