import { menu, Menu } from "config/menu"; import React, { Fragment } from "react"; import { useHistory } from "react-router-dom"; import "./Sidebar.scss"; import SidebarItem from "./SidebarItem"; import SidebarMenu from "./SidebarMenu"; interface SidebarProps { menus?: Menu[]; } function Sidebar(props: SidebarProps) { const { menus } = props; const [listActiveMenu, setListActiveMenu] = React.useState([]); const history = useHistory(); const handleActiveMenu = React.useCallback((path: string) => { setListActiveMenu([path]); }, []); React.useEffect(() => { return history.listen((location) => { handleActiveMenu(location.pathname); }); }, [handleActiveMenu, history]); React.useEffect(() => { handleActiveMenu(window.location.pathname); }, [handleActiveMenu]); const renderMenu = React.useCallback( (listMenu: Menu[], level = 1) => { return listMenu.map((item, index) => { if (item.children && item.children.length > 0) { return ( {item.show && ( )} ); } return ( {item.show && ( )} ); }); }, [listActiveMenu] ); return (
M
Side Menu Level 1
Side Menu Level 1
); } export default Sidebar;