mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-08 04:43:00 +08:00
25 lines
583 B
TypeScript
25 lines
583 B
TypeScript
import { useState, useEffect } from 'react';
|
|
|
|
function getWindowDimensions() {
|
|
const { innerWidth: width, innerHeight: height } = window;
|
|
return {
|
|
width,
|
|
height,
|
|
};
|
|
}
|
|
|
|
export default function useWindowDimensions() {
|
|
const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());
|
|
|
|
useEffect(() => {
|
|
function handleResize() {
|
|
setWindowDimensions(getWindowDimensions());
|
|
}
|
|
|
|
window.addEventListener('resize', handleResize);
|
|
return () => window.removeEventListener('resize', handleResize);
|
|
}, []);
|
|
|
|
return windowDimensions;
|
|
}
|