Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JSX element type 'Icon' does not have any construct or call signatures

I am relatively new to typescript and trying to diagnose an error. I’m making sidebar navigation and trying to pull an icon from my navigation array.

Array:

    const menuItems = [
        { id: 1, label: "Dashboard", icon: <ComputerDesktopIcon />, link: "/" },
        { id: 2, label: "Page 2", icon: <AcademicCapIcon />, link: "" },
        { id: 3, label: "Settings", icon: <Cog6ToothIcon />, link: "/" },
    ];

In my code, the error is stemming from this section:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<div className="flex flex-col items-start mt-24">
                    {menuItems.map(({ icon: Icon, ...menu }) => {
                        const classes = getNavItemClasses(menu);

                        return <div className={classes}>
                            <Link href={menu.link}>
                                <div className="flex py-2 px-3 items-center w-full h-full">
                                    <div>
                                        <Icon />
                                    </div>
                                    {!toggleCollapse && (
                                        <span className={classNames('text-md font-medium text-dark-gray')}>
                                            {menu.label}
                                        </span>
                                    )}
                                </div>
                            </Link>
                        </div>
                    })}
                </div>

Specifically the <Icon /> call is throwing the error: JSX element type 'Icon' does not have any construct or call signatures.

Worth noting everything works perfectly when that line is commented out.

I’ve worked through building props components and other Stack Overflow issues, but where I’m getting caught is in the menuItems.map section… most tutorials only define creating + implementing single const items.

>Solution :

JSX element type ‘Icon’ does not have any construct or call signatures

icon is already a called react component that returns JSX.

Simply replace </> with curly braces {}.

{menuItems.map(({ icon, ...menu }) => {
   ...
   {icon}
   ...
})}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading