Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

358
Vistas
How to include an image into a Select Option label, React?

I am new to React and I am trying to create a drop-down with images in the labels and I am using a function to get the values from a map and build an id: label pair to show as options in the drop-down. where both id and label are of string type.

I am trying to retrieve the options like this:

const options = (): Select.Option[] => {
  return VALUES.map((color) => convertIdtoSelect(color));
};

where, VALUES is of type:

export const VALUES: ValueDef[] = [
 {
   id: 'blue'
   name: 'Blue Color'
 },
 {
   id: 'red'
   name: 'Red color'
 },
];

Here the method convertIdtoSelect looks like:

export function convertIdtoSelect(color: ValueDef): Select.Option {
 return {
  id: color.id,
  label: `${color.name}` // Insert an image in this label that I have in a directory, before the name.
 };
}

Please let me know how do I do this. I tried:

label: `<div><img src={/img/src/${color.id}.png} height="30px" width="30px"/> ${color.name} </div>`,

which doesn't work. Please let me know what I am doing wrong and thanks in advance for any help and suggestions.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Since it's React you can pass JSX directly into the object

export function convertIdtoSelect(color: ValueDef): Select.Option {
 return {
  id: color.id,
  label: <div><img src={`/img/src/${color.id}.png`} height="30px" width="30px">{color.name}</div> // Insert an image in this label that I have in a directory, before the name.
 };
}

And then just render it using {item.label} (assuming item is the variable returned from the function)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda