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

169
Vistas
How to dynamically insert a local variable in to a react JSX map function?

I have this component, that inherits a props with a value of string 'A','B','C' depending on what is getting selected at a parent element the point being is the props.options either 'A' or 'B' or 'C' then I want to leverage this incoming props to be able to select a local option list from options array.. depending on what is being passed down instead of passing the whole options arrays from the parent down to child component... I am trying to use template literals but it's not working any local work around so I could render the options array depending on incoming string props? for this particular case.

// incoming props  string of A or  B or  C depending on what is getting seleted at parent element ! 

function OptionAcordingToProps(props) {
 
 const optionsA = ['x', 'x', 'x'];
 const optionsB = ['y', 'y', 'y'];
 const optionsC = ['z', 'z', 'z'];
 
  return (
    <div>
      <form onSubmit={doSmth}>
        <NativeSelect>
             {`options${props.options}`?.map((option) => (
            <option>{option}</option>
          ))}
        </NativeSelect>
        </form>    
       </div>
  );
}

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

0

Use an object as a map:

function OptionAcordingToProps(props) {
 
  const options = {
     A: ['x', 'x', 'x'],
     B: ['y', 'y', 'y'],
     C: ['z', 'z', 'z'],
  };
 
  return (
    <div>
      <form onSubmit={doSmth}>
        <NativeSelect>
             {options[props.options]?.map((option) => (
            <option>{option}</option>
          ))}
        </NativeSelect>
        </form>    
       </div>
  );
}
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