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

Type 'IconType' is not assignable to type 'ReactNode'

have been looking for a way to properly render an icon in my component but ended up with an error from the title.

Profile.tsx:

<ul>
  {socialLinks.map((socialLink) => (
    <li key={socialLink.href}>
      <a href={socialLink.href}>{socialLink.icon}</a>
    </li>
  ))}
</ul>

data.ts

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

import { FaDiscord, FaGithub, FaTwitter } from "react-icons/fa";

export const socialLinks = [
  {
    name: "github",
    href: "#",
    icon: FaGithub,
  },
  {
    name: "twitter",
    href: "#",
    icon: FaTwitter,
  },
  {
    name: "discord",
    href: "#",
    icon: FaDiscord,
  },
];

is there a way to fix this?

>Solution :

The icon is a functional component. You have to invoke it.

Either, invoke it directly in the data config:

{ icon: <FaGithub />, name: ..., href: ... }

or when mapping:

{socialLinks.map((socialLink) => {
   const Icon = socialLink.icon;

   return (
     <li key={socialLink.href}>
       <a href={socialLink.href}>
         <Icon />
       </a>
    </li>
   );
))}
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