1import { useEffect, useState } from 'react';
2
3export function useScreenWidth(): number {
4 const [width, setWidth] = useState(window.innerWidth);
5
6 useEffect(() => {
7 const handler = (event: any) => {
8 setWidth(event.target.innerWidth);
9 };
10
11 window.addEventListener('resize', handler);
12
13 return () => {
14 window.removeEventListener('resize', handler);
15 };
16 }, []);
17
18 return width;
19}
20