Skip to content

RAC better example of splitting Menu into constituent parts for better decoupling #4906

Answered by devongovett
binaryartifex asked this question in Q&A
Discussion options

You must be logged in to vote

Looks like it should work, but you might be able to simplify it a little? I think the Root component is almost identical to the builtin MenuTrigger component, which also calls useMenuTrigger and provides the same contexts. The MenuList component probably doesn't need to consume from the PopoverContext or MenuContext, because the Popover and Menu components you're wrapping already do that. So that just leaves Trigger. I can't tell based on the code example, but if <Button> is using a React Aria Components Button internally, then that will also already consume from the ButtonContext and you shouldn't need the Trigger wrapper at all.

import {MenuTrigger, Popover, Menu, Section, Item} from 'r…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@devongovett
Comment options

Answer selected by binaryartifex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants