Dropdown menu item cannot use hooks #1349
-
I am adding Looking at |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The menuItems prop is supposed to be an array of functions which return a component, rather than an array of components. You can fix it like this: function ContextItem({ onClick, ...props }: React.ComponentPropsWithoutRef<typeof MenuItem>) {
const { message } = React.useContext(internalContext);
return (
<MenuItem
onClick={(...args) => {
console.log(`Context Item Clicked - ${message}`);
onClick?.(...args);
}}
{...props}
>
ContextItem
</MenuItem>
);
} - ContextItem,
+ ({ close }) => <ContextItem onClick={close} />, |
Beta Was this translation helpful? Give feedback.
The menuItems prop is supposed to be an array of functions which return a component, rather than an array of components.
You can fix it like this: