Showing
2 changed files
with
17 additions
and
0 deletions
project/packages/web/src/hooks/index.ts
0 → 100644
1 | +export { default as useWindowSize } from './useWindowSize'; |
1 | +import { useLayoutEffect, useState } from 'react'; | ||
2 | + | ||
3 | +export default function useWindowSize() { | ||
4 | + const [size, setSize] = useState([0, 0]); | ||
5 | + | ||
6 | + useLayoutEffect(() => { | ||
7 | + function updateSize() { | ||
8 | + setSize([window.innerWidth, window.innerHeight]); | ||
9 | + } | ||
10 | + window.addEventListener('resize', updateSize); | ||
11 | + updateSize(); | ||
12 | + return () => window.removeEventListener('resize', updateSize); | ||
13 | + }, []); | ||
14 | + | ||
15 | + return size; | ||
16 | +} |
-
Please register or login to post a comment