Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/hooks/useMenuItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ export const useMenuItems = (
menuBarItems,
);

// A host that passes menuBarItems has already rendered the menu it shipped
// with, so fetching would only replace correct data with whatever the API's
// caches are still holding. Only hosts that supply nothing need the fetch.
useEffect(() => {
if (menuBarItems) {
setMenuItems(menuBarItems);
return;
}

refreshData()
.then((data) => {
setMenuItems(data);
Expand All @@ -45,12 +53,6 @@ export const useMenuItems = (
// eslint-disable-next-line no-console
console.error(err);
});
}, []);

useEffect(() => {
if (menuBarItems) {
setMenuItems(menuBarItems);
}
}, [menuBarItems]);

return { menuItems: menuItems || [] };
Expand Down
Loading