Skip to content

Commit

Permalink
fix: missing dependencies on fixed position hook effect
Browse files Browse the repository at this point in the history
  • Loading branch information
rortan134 authored Jan 26, 2024
1 parent f17c93f commit 8b9288a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/use-position-fixed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function usePositionFixed({
const [activeUrl, setActiveUrl] = React.useState(typeof window !== 'undefined' ? window.location.href : '');
const scrollPos = React.useRef(0);

function setPositionFixed() {
const setPositionFixed = React.useCallback(() => {
// If previousBodyPosition is already set, don't set it again.
if (previousBodyPosition === null && isOpen) {
previousBodyPosition = {
Expand Down Expand Up @@ -48,9 +48,9 @@ export function usePositionFixed({
300,
);
}
}
}, [isOpen]);

function restorePositionSetting() {
const restorePositionSetting = React.useCallback(() => {
if (previousBodyPosition !== null) {
// Convert the position from "px" to Int
const y = -parseInt(document.body.style.top, 10);
Expand All @@ -74,7 +74,7 @@ export function usePositionFixed({

previousBodyPosition = null;
}
}
}, [activeUrl]);

React.useEffect(() => {
function onScroll() {
Expand Down Expand Up @@ -104,7 +104,7 @@ export function usePositionFixed({
} else {
restorePositionSetting();
}
}, [isOpen, hasBeenOpened, activeUrl]);
}, [isOpen, hasBeenOpened, activeUrl, modal, nested, setPositionFixed, restorePositionSetting]);

return { restorePositionSetting };
}

0 comments on commit 8b9288a

Please sign in to comment.