@redocly/theme
Version:
Shared UI components lib
26 lines (18 loc) • 671 B
text/typescript
import { useEffect, useState } from 'react';
import type { Location } from 'react-router-dom';
import { getNavbarElement } from '../utils/get-navbar-element';
export type UseNavbarHeightReturnType = number;
export function useNavbarHeight(location: Location): UseNavbarHeightReturnType {
const [height, setHeight] = useState(0);
useEffect(() => {
const navbar = getNavbarElement();
setHeight((navbar && navbar.clientHeight) || 0);
}, [location.pathname]);
useEffect(() => {
window.requestAnimationFrame(() => {
const navbar = getNavbarElement();
setHeight((navbar && navbar.clientHeight) || 0);
});
}, []);
return height;
}