From cf772fc02ecfa63b6bfe9d823d6f5d35f89bfe1a Mon Sep 17 00:00:00 2001 From: Philipp Hugenroth Date: Mon, 24 Jan 2022 10:18:41 +0100 Subject: [PATCH] Fix unnecessary recreation of react element Signed-off-by: Philipp Hugenroth --- packages/core-components/src/layout/Sidebar/Items.tsx | 6 +++--- .../core-components/src/layout/Sidebar/MobileSidebar.tsx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/core-components/src/layout/Sidebar/Items.tsx b/packages/core-components/src/layout/Sidebar/Items.tsx index aeac9aebf9..fc97fdc0ce 100644 --- a/packages/core-components/src/layout/Sidebar/Items.tsx +++ b/packages/core-components/src/layout/Sidebar/Items.tsx @@ -284,6 +284,8 @@ function isButtonItem( return (props as SidebarItemLinkProps).to === undefined; } +const sidebarSubmenuType = React.createElement(SidebarSubmenu).type; + // TODO(Rugvip): Remove this once NavLink is updated in react-router-dom. // This is needed because react-router doesn't handle the path comparison // properly yet, matching for example /foobar with /foo. @@ -490,9 +492,7 @@ export const SidebarItem = forwardRef((props, ref) => { // combination with react-hot-loader // // https://github.com/gaearon/react-hot-loader/issues/304#issuecomment-456569720 - elements - .getElements() - .filter(child => child.type === React.createElement(SidebarSubmenu).type), + elements.getElements().filter(child => child.type === sidebarSubmenuType), ); if (submenu) { diff --git a/packages/core-components/src/layout/Sidebar/MobileSidebar.tsx b/packages/core-components/src/layout/Sidebar/MobileSidebar.tsx index cd6d5defb1..95947f9274 100644 --- a/packages/core-components/src/layout/Sidebar/MobileSidebar.tsx +++ b/packages/core-components/src/layout/Sidebar/MobileSidebar.tsx @@ -102,6 +102,8 @@ const sortSidebarGroupsForPriority = (children: React.ReactElement[]) => 'desc', ); +const sidebarGroupType = React.createElement(SidebarGroup).type; + const OverlayMenu = ({ children, label = 'Menu', @@ -168,9 +170,7 @@ export const MobileSidebar = (props: MobileSidebarProps) => { // // https://github.com/gaearon/react-hot-loader/issues/304#issuecomment-456569720 let sidebarGroups = useElementFilter(children, elements => - elements - .getElements() - .filter(child => child.type === React.createElement(SidebarGroup).type), + elements.getElements().filter(child => child.type === sidebarGroupType), ); if (!children) {