Menu Item template

UI Components for React
Post Reply
bjedrzejec
Posts: 1
Joined: 07 Apr 2021, 00:19

07 Apr 2021, 00:35

Hi,
I want to create a menu item template to use the Link element from react-router-dom. The following code:

const items = [
{
label: "New",
template: (item, options) => {
return (
<Link to = {"/ create"} className = {options.className}>
<span
className = {classNames (options.iconClassName, "pi pi-plus")}
> </span>
{item.label}
</Link>
);
},
},
];
works fine for a project without TypeScript, unfortunately I get the following error in a project that uses TypeScript:

Overload 1 of 2, '(props: MenubarProps | Readonly <MenubarProps>): Menubar', gave the following error.
Type '{label: string; template: (item: any, options: any) => Item; } [] 'is not assignable to type' MenuItem [] '.
Type '{label: string; template: (item: any, options: any) => Item; } 'is not assignable to type' MenuItem '.
Types of property 'template' are incompatible.
Type '(item: any, options: any) => Element' is not assignable to type 'string | Element | undefined '.
Type '(item: any, options: any) => Element' is missing the following properties from type 'Element': type, props, key
Overload 2 of 2, '(props: MenubarProps, context: any): Menubar', gave the following error.
Type '{label: string; template: (item: any, options: any) => Item; } [] 'is not assignable to type' MenuItem [] '. TS2769

I suspect a data type problem but have no idea how to fix it.

I will be grateful for your help.

Regards,
Bart

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests