1import { useState } from "react";
2
3/** Clear portaled menus when their measured, still-mounted triggers hide. */
4export function useComposerMenuState(hidden = false) {
5 const [open, setOpen] = useState(false);
6 // Base UI does not notify us when we close it by changing its open prop.
7 // Reset the stored state too, so revealing the trigger cannot reopen it.
8 if (hidden && open) {
9 setOpen(false);
10 }
11 return [open && !hidden, setOpen] as const;
12}