1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

fixed getScrollHeight

This commit is contained in:
Fedor Katurov 2022-01-11 11:31:42 +07:00
parent 8d1e6989c2
commit 0a9b4b6388

View file

@ -1,5 +1,3 @@
import { useEffect, useState } from 'react';
const getHeight = () => {
if (typeof document === 'undefined') {
return 0;
@ -16,20 +14,4 @@ const getHeight = () => {
html.offsetHeight
);
};
export const useScrollHeight = () => {
const [scrollHeight, setScrollHeight] = useState(getHeight());
useEffect(() => {
const measure = () => setScrollHeight(getHeight());
window.addEventListener('scroll', measure);
window.addEventListener('resize', measure);
return () => {
window.removeEventListener('scroll', measure);
window.removeEventListener('resize', measure);
};
}, []);
return scrollHeight;
};
export const useScrollHeight = () => getHeight();