mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
fixed getScrollHeight
This commit is contained in:
parent
8d1e6989c2
commit
0a9b4b6388
1 changed files with 1 additions and 19 deletions
|
@ -1,5 +1,3 @@
|
||||||
import { useEffect, useState } from 'react';
|
|
||||||
|
|
||||||
const getHeight = () => {
|
const getHeight = () => {
|
||||||
if (typeof document === 'undefined') {
|
if (typeof document === 'undefined') {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -16,20 +14,4 @@ const getHeight = () => {
|
||||||
html.offsetHeight
|
html.offsetHeight
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export const useScrollHeight = () => {
|
export const useScrollHeight = () => getHeight();
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue