Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

67
Vistas
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

7 months ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

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>
7 months ago · Juan Pablo Isaza Denunciar

0

const SocialMedia = () => {
    let socialLink = {
        instagram: 'https://twitter.com/xyz',
        facebook: 'https://facebook.com/xyz',
        twitter: 'https://twitter.com/xyz'
    }
    return (
        <div>
            {
                Object.keys(socialLink).map((key, index) => {
                    return (
                        <a href={socialLink[key]} key={index}>
                            <image src={key+'.png'} />
                        </a>
                    )
                })
            }
        </div>
    )
}
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos