Files
xyflow/website/src/hooks/useMenuHeight.js
2020-10-05 18:42:51 +02:00

24 lines
511 B
JavaScript

import { useState, useEffect } from 'react';
const getInnerHeight = () => {
return typeof window !== 'undefined' ? window.innerHeight : 0;
};
export default function useMenuHeight() {
const [menuHeight, setMenuHeight] = useState(getInnerHeight());
useEffect(() => {
const onResize = () => {
setMenuHeight(getInnerHeight());
};
window.addEventListener('resize', onResize);
return () => {
window.removeEventListener('resize', onResize);
};
});
return menuHeight;
}