Skip to content

Commit

Permalink
브라우저 너비를 계산하는 커스텀 훅 생성
Browse files Browse the repository at this point in the history
브라우저 너비를 계산하는 커스텀 훅 생성
  • Loading branch information
BearHumanS authored Jan 26, 2024
2 parents 9066e7c + 3cf91ed commit d9528c7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/hook/useCalculateInnerWidth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useEffect, useState } from 'react';

const useCalculateInnerWidth = () => {
const [windowWidth, setWindowWidth] = useState(window.innerWidth);

useEffect(() => {
const handleResize = () => {
setWindowWidth(window.innerWidth);
};

window.addEventListener('resize', handleResize);

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

return windowWidth;
};

export default useCalculateInnerWidth;

0 comments on commit d9528c7

Please sign in to comment.