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:
parent
8d1e6989c2
commit
0a9b4b6388
1 changed files with 1 additions and 19 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue