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 use this map function in React to call url with images name

  socialLinks: {
    instagram: 'https://twitter.com/xyz',
    facebook: 'https://facebook.com/xyz',
    linkedin: '#',
  },

how to create a loop so that result should come like this –

<div>
   <a href="https://instagram.com/xyz">
      <image src="instagram.png" />
   </a>
   <a href="https://facebook.com/xyz">
      <image src="facebook.png" />
   </a>
<div>

Note: If there is no link of linkedin then no link and image will come

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 :

You can take advantage of Object.entries:

<div>
    {
        Object.entries(socialLinks).filter(([k,v]) => v.startsWith("https:")).map(([k,v]) => 
            <a key={v} href={v}>
                <image src={`${k}.png`} />
            </a>
        )
    }
</div>
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