mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
15 lines
409 B
TypeScript
15 lines
409 B
TypeScript
import { useLayoutEffect, useState } from 'react';
|
|
|
|
export function useWindowSize() {
|
|
const [size, setSize] = useState([0, 0]);
|
|
useLayoutEffect(() => {
|
|
function updateSize() {
|
|
setSize([window.innerWidth, window.innerHeight]);
|
|
}
|
|
window.addEventListener('resize', updateSize);
|
|
updateSize();
|
|
return () => window.removeEventListener('resize', updateSize);
|
|
}, []);
|
|
return size;
|
|
}
|