Browse Source

Prevent nav context re-renders (#4266)

main
dan 3 years ago
committed by GitHub
parent
commit
58d6f3f9fc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      beta/src/components/useMenu.tsx

18
beta/src/components/useMenu.tsx

@ -51,13 +51,17 @@ export const useMenu = () => {
};
}, [router.pathname, hideSidebar]);
return {
hideSidebar,
showSidebar,
toggleOpen,
menuRef,
isOpen,
};
// Avoid top-level context re-renders
return React.useMemo(
() => ({
hideSidebar,
showSidebar,
toggleOpen,
menuRef,
isOpen,
}),
[]
);
};
export const MenuContext = React.createContext<ReturnType<typeof useMenu>>(

Loading…
Cancel
Save