Skip to content

Commit

Permalink
fix: Move viewport declaration inside useEffect for accurate window d…
Browse files Browse the repository at this point in the history
…imension updates
  • Loading branch information
TobiTRy committed Dec 16, 2024
1 parent 2f1cc6a commit db1e838
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils/hooks/useWindowDimensions/useWindowDimensions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ function getWindowDimensions(vp?: VisualViewport | null) {
export default function useWindowDimensions() {
const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());

const viewport = window.visualViewport;

// This useEffect hook adds a window resize event listener and removes it on cleanup
useEffect(() => {
const viewport = window.visualViewport;

function handleResize() {
setWindowDimensions(getWindowDimensions(viewport));
}
Expand Down

0 comments on commit db1e838

Please sign in to comment.