diff --git a/src/layout/sidebar/Sidebar.tsx b/src/layout/sidebar/Sidebar.tsx index 91a4952..35a5ce3 100644 --- a/src/layout/sidebar/Sidebar.tsx +++ b/src/layout/sidebar/Sidebar.tsx @@ -1,9 +1,9 @@ // Copyright (c) 2020-2021 Drew Lemmy // This file is part of KristWeb 2 under AGPL-3.0. // Full details: https://github.com/tmpim/KristWeb2/blob/master/LICENSE.txt -import { useState, useEffect, Dispatch, SetStateAction } from "react"; +import { useState, useEffect, useMemo, Dispatch, SetStateAction } from "react"; import { Layout, Menu, MenuItemProps } from "antd"; -import { HomeOutlined, WalletOutlined, TeamOutlined, BankOutlined, TagsOutlined, SketchOutlined, BuildOutlined, StockOutlined } from "@ant-design/icons"; +import { HomeOutlined, WalletOutlined, TeamOutlined, BankOutlined, TagsOutlined, BuildOutlined } from "@ant-design/icons"; import { TFunction, useTranslation } from "react-i18next"; import { useLocation } from "react-router-dom"; @@ -71,34 +71,38 @@ setSelectedKey(sidebarItems.find(i => i.to === "/" ? location.pathname === "/" : location.pathname.startsWith(i.to))?.to); - }, [location]); + }, [location.pathname]); useEffect(() => { // Close the sidebar if we switch page setCollapsed(true); }, [setCollapsed, location.pathname]); - return - {/* Service worker update checker, which may appear at the top of the - * sidebar if an update is available. */} - + const memoSidebar = useMemo(() => ( + + {/* Service worker update checker, which may appear at the top of the + * sidebar if an update is available. */} + - {/* Total balance */} - + {/* Total balance */} + - {/* Menu items */} - - {getSidebarItems(t)} + {/* Menu items */} + + {getSidebarItems(t)} - - {getSidebarItems(t, "network")} - - + + {getSidebarItems(t, "network")} + + - {/* Credits footer */} - - ; + {/* Credits footer */} + + + ), [t, collapsed, selectedKey]); + + return memoSidebar; }