-1

I have a code like this I want to change the tag name starting with <all.

{services.map((item) => (
        <div className="space-x-[8px] py-[8px] flex ">
        <div className="flex flex-col text-center relative px-[8px] py-[8px] items-center active:bg-[#f5f5f5]  cursor-pointer">
          <All.${item}
            sx={{ fontSize: "40px" }}
            className="text-[#6B84DD] w-[64px] h-[p64x] text-3xl"
          />
          <span className=" font-merrisans text-[14px] font-semibold">
            {item}
          </span>
        </div>
      </div>
      ))}

I tried like this

{services.map((item) => (
        <div className="space-x-[8px] py-[8px] flex ">
        <div className="flex flex-col text-center relative px-[8px] py-[8px] items-center active:bg-[#f5f5f5]  cursor-pointer">
          {(`{<All.${item}
            sx={{ fontSize: "40px" }}
            className="text-[#6B84DD] w-[64px] h-[p64x] text-3xl"
          />`)}
          <span className=" font-merrisans text-[14px] font-semibold">
            {item}
          </span>
        </div>
      </div>
      ))}

but it didn't worked it showing

1 Answers1

0

JSX is not a string, you can't use ${}

{
  services.map((item) => {
    const Component = All[item];
    return (
      <div className="space-x-[8px] py-[8px] flex ">
        <div className="flex flex-col text-center relative px-[8px] py-[8px] items-center active:bg-[#f5f5f5]  cursor-pointer">
          <Component
            sx={{ fontSize: "40px" }}
            className="text-[#6B84DD] w-[64px] h-[p64x] text-3xl"
          />
          <span className=" font-merrisans text-[14px] font-semibold">
            {item}
          </span>
        </div>
      </div>
    );
  });
}
Konrad
  • 21,590
  • 4
  • 28
  • 64
  • It is showing..... The tag is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter. – Shashank Singh Mar 20 '23 at 18:12
  • @ShashankSingh you didn't really show what is `All`. Seems like `All.something` is not a react component but a string – Konrad Mar 20 '23 at 19:49
  • Actually I imported some icons from a js file as All. that's why i am using All.item. but even now i have imported them singularly. It is treating Component as a String not referencing to the actual imported icon. – Shashank Singh Mar 21 '23 at 04:08