Fix component type comparison in Sidebar

Signed-off-by: Philipp Hugenroth <philipph@spotify.com>
This commit is contained in:
Philipp Hugenroth
2022-01-21 14:45:33 +01:00
parent b53a1afd67
commit 41f4f2dd88
2 changed files with 15 additions and 2 deletions
@@ -486,7 +486,13 @@ const SidebarItemWithSubmenu = ({
export const SidebarItem = forwardRef<any, SidebarItemProps>((props, ref) => {
// Filter children for SidebarSubmenu components
const [submenu] = useElementFilter(props.children, elements =>
elements.getElements().filter(child => child.type === SidebarSubmenu),
// Directly comparing child.type with SidebarSubmenu will not work with in
// 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),
);
if (submenu) {
@@ -162,8 +162,15 @@ export const MobileSidebar = (props: MobileSidebarProps) => {
}, [location.pathname]);
// Filter children for SidebarGroups
//
// Directly comparing child.type with SidebarSubmenu will not work with in
// combination with react-hot-loader
//
// https://github.com/gaearon/react-hot-loader/issues/304#issuecomment-456569720
let sidebarGroups = useElementFilter(children, elements =>
elements.getElements().filter(child => child.type === SidebarGroup),
elements
.getElements()
.filter(child => child.type === React.createElement(SidebarGroup).type),
);
if (!children) {