Files
real-time-fund/app/hooks/useBodyScrollLock.js
2026-03-12 21:53:11 +08:00

18 lines
404 B
JavaScript

import { useEffect } from "react";
export function useBodyScrollLock(open) {
useEffect(() => {
if (!open) return;
const scrollY = window.scrollY;
document.body.style.position = "fixed";
document.body.style.top = `-${scrollY}px`;
return () => {
document.body.style.position = "";
document.body.style.top = "";
window.scrollTo(0, scrollY);
};
}, [open]);
}