Skip to content

Commit

Permalink
add custom hook for viewport dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
deveshidwivedi committed Jun 18, 2024
1 parent ff17659 commit b349a55
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions common/hooks/useViewportSize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {useEffect, useState} from "react";

export const useViewportSize = () => {

const [width, setWidth]= useState(0);
const [height, setHeight]= useState(0);

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

window.addEventListener("resize", handleResize);
handleResize();

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

0 comments on commit b349a55

Please sign in to comment.