-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Navigation component: Store navigation tree in context #25292
Conversation
Size Change: +368 B (0%) Total Size: 1.2 MB
ℹ️ View Unchanged
|
|
||
setNavigationItems( items ); | ||
setNavigationMenus( menus ); | ||
}, [] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Children might change after mount (e.g. dynamically fetched menu items), so we can't use the empty dependency array here.
But children is not a primitive, so using it as a dependency would run useEffect
at every render, which might be a performance problem.
I'm not sure how to solve this conundrum, though. 🤔
}; | ||
|
||
return innerRecursion( initialChildren, null ); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll happily leave someone else to review the recursion. 😄
I think this is getting to a good place. Some other points of discussions:
const navigationTree = {
menu1: {
...props,
children: {
item1: { ...props },
item2: { ...props },
}
},
};
|
Agreed, we might want to change the data structure behind the scenes so an abstraction is always a good idea to keep it compatible.
Nested structure is a nightmare to work with. I don't see any pros using a nested structure for storing the data. We can easily access anything we want with key-based approach. Though we could have both structure available.
A unique ID is a must for easy management IMO. Without that many tasks would become impossible or hacky.
Yeah sure. That sounds a good idea. Though I'm not sure if you can utilise it in your PR the way you would like to do. |
All right, let's assume that
Yeah I guess marking items with their |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the approach that you proposed in #25340 so I'll continue reviewing and commenting there. :)
Closing this as replaced by #25340 |
Fixes: #25246
Description
Adds
items
andmenus
to the Navigation context.Example usage: Change back button label to the parent menu's title
packages/components/src/navigation/menu.js
Both
items
andmenus
are objects.Keys are based on the
item
prop foritems
and they are based onmenu
prop formenus
. This makes them easily accessible by their slug.Values are the props of the
NavigationItem
andNavigationMenu
items without thechildren
prop. Items also include the menu that contains the item asmenu
property.Types of changes
New feature (non-breaking change which adds functionality)
Checklist: