I have a very simple dropdown menu. By clicking on the icon NewIcon in DropdownMenu.Trigger, the user sees a drop-down menu. Everything is simple here. To implement the dropdown menu, I use the radix library (https://www.radix-ui.com/primitives/docs/components/dropdown-menu)
<DropdownMenu.Root open={isOpen} onOpenChange={setIsOpen}>
<DropdownMenu.Trigger>
<NewIcon/>
</DropdownMenu.Trigger>
<DropdownMenu.Portal forceMount>
<DropdownMenu.Content>
........here some components
</DropdownMenu.Content>
</DropdownMenu.Portal>
</DropdownMenu.Root>
However, I would like to also call this dropdown menu with another button (which is located in another component) on the same page.
For example, below is another component that renders the "Edit information" button. Tell me how to click on this button to open the dropdown menu
<div>
<Button>
Edit information
</Button>
<div>
2
Answers
The DropdownMenu’s open state is controlled by
isOpen
So you can just do this
It seems that all you need to do is create a dispatcher that will switch the state to trigger a re-render of the page.
You can use that with any state manager you prefer. The only thing that will change is the location where the data is stored.