Fix unnecessary recreation of react element
Signed-off-by: Philipp Hugenroth <philipph@spotify.com>
This commit is contained in:
@@ -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<any, SidebarItemProps>((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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user