Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 25 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 100% |
Changes | 0 |
1 | import { useState, useEffect } from 'react' |
||
2 | import { getWindowDimensions } from '~/modules/core/utils/helpers' |
||
3 | |||
4 | /* istanbul ignore next */ |
||
5 | 11 | const useWindowDimensions = () => { |
|
6 | 23 | const [windowDimensions, setWindowDimensions] = useState( |
|
7 | getWindowDimensions() |
||
8 | ) |
||
9 | |||
10 | 23 | useEffect(() => { |
|
11 | /* istanbul ignore next */ |
||
12 | function handleResize() { |
||
13 | setWindowDimensions(getWindowDimensions()) |
||
14 | } |
||
15 | |||
16 | 22 | window.addEventListener('resize', handleResize) |
|
17 | /* istanbul ignore next */ |
||
18 | return () => window.removeEventListener('resize', handleResize) |
||
19 | }, []) |
||
20 | |||
21 | 23 | return windowDimensions |
|
22 | } |
||
23 | |||
24 | export default useWindowDimensions |
||
25 |