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

How to load Image or svg src through react map from states?

https://codesandbox.io/s/load-svg-from-import-via-states-6ycf4q

I am trying to load svg icons in map from state objects but the state is not loading in img src. please help

   {Tabs.map((obj, i) => (
                  <Card className="">
                    <Card.Body>
                      <i className={obj.icon}></i>
                      <img src={obj.iconsvg} />
                      <Card.Title>{obj.tabtitle}</Card.Title>
                      <Card.Link
                        key={i}
                        onClick={() => setActive(obj.tabname)}
                        className="tab"
                      >
                        Click to see more <img src={linkarrow} />
                      </Card.Link>
                    </Card.Body>
                  </Card>
                ))}

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

>Solution :

Since you import your icons as

import cardicon1 from "./cardicon1.svg";

you must reference this at your iconsvg property

  {
    tabname: "tab2",
    tabtitle: "Chart Color Pale111ttes",
    icon: "fas fa-palette",
    iconsvg: cardicon1
  },

Check this sandbox

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