Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed Apr 22, 2024
1 parent a46ec33 commit 4be89d3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions coding_interviews/frontend/react/useWindowSize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useState, useEffect } from 'react';

function useWindowSize() {
const [height, setHeight] = useState(window.innerHeight);
const [width, setWidth] = useState(window.innerWidth);

useEffect(() => {
const handleResize = () => {
setHeight(window.innerHeight);
setWidth(window.innerWidth);
};

window.addEventListener('resize', handleResize);

return () => {
window.removeEventListener('resize', handleResize);
};
}, []);

return { width, height };
}

0 comments on commit 4be89d3

Please sign in to comment.