Skip to content

Commit

Permalink
feat: add hook use dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
ialexanderbrito committed Apr 6, 2022
1 parent d995e76 commit b6bb28e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/hooks/useDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useEffect, useRef, useState } from 'react';

export function useDropdown() {
const [activeMenu, setActiveMenu] = useState('main');
const [menuHeight, setMenuHeight] = useState<any>(null);
const dropdownRef = useRef<any>(null);

function calcHeight(el: { offsetHeight: any }) {
const height = el.offsetHeight;
setMenuHeight(height);
}

useEffect(() => {
setMenuHeight(dropdownRef.current?.firstChild.offsetHeight + 30);
}, []);

return {
activeMenu,
setActiveMenu,
menuHeight,
setMenuHeight,
dropdownRef,
calcHeight,
};
}

0 comments on commit b6bb28e

Please sign in to comment.