mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-27 21:40:36 +03:00
33 lines
731 B
TypeScript
33 lines
731 B
TypeScript
'use client';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
function useWindowSize() {
|
|
const isClient = typeof window === 'object';
|
|
|
|
function getSize() {
|
|
return {
|
|
width: isClient ? window.innerWidth : undefined,
|
|
height: isClient ? window.innerHeight : undefined
|
|
};
|
|
}
|
|
|
|
const [windowSize, setWindowSize] = useState(getSize);
|
|
|
|
useEffect(
|
|
() => {
|
|
if (!isClient) {
|
|
return;
|
|
}
|
|
function handleResize() {
|
|
setWindowSize(getSize());
|
|
}
|
|
window.addEventListener('resize', handleResize);
|
|
return () => window.removeEventListener('resize', handleResize);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
|
|
return windowSize;
|
|
}
|
|
|
|
export default useWindowSize; |