|
Ultima modificación |
Ver Log
|
| Rev |
Autor |
Línea Nro. |
Línea |
| 4946 |
stevensc |
1 |
import { useLayoutEffect, useState } from 'react';
|
|
|
2 |
|
|
|
3 |
function useWindowSize() {
|
|
|
4 |
const [size, setSize] = useState([0, 0]);
|
|
|
5 |
useLayoutEffect(() => {
|
|
|
6 |
function updateSize() {
|
|
|
7 |
setSize([window.innerWidth, window.innerHeight]);
|
|
|
8 |
}
|
|
|
9 |
window.addEventListener('resize', updateSize);
|
|
|
10 |
updateSize();
|
|
|
11 |
return () => window.removeEventListener('resize', updateSize);
|
|
|
12 |
}, []);
|
|
|
13 |
return size;
|
|
|
14 |
}
|
|
|
15 |
|
|
|
16 |
export default useWindowSize
|