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

150
Vistas
Get array of components by assigning array of values to props

Suppose that we have a component with 2 props:

const component = (props) =>{

      return <div> {props.text1} {props.text2} </div>

}

I would like to create an array of the above component with different props values

[<component text1=1 text2=-1>, <component text1=2 text2=-2>,...,<component text1=n text2=-n>]

Since I am using this so often I am looking to define a function for it rather than writing for loops every time.

Specifically, I am looking for implementation of a jsx function

componentArray(Component,propsArray,valueMatrix,repeatedTimes){
   
   // Column of the valueMatrix corresponds values to be assigned for one props
   // Below are not legit javascript code, just for illustration purposes

   let array = [];
   for (i=0, i<repeatedTimes, i+1){

       array.push(<Component
 
                     propsArray[0] = valueMatrix[0,i],
                     propsArray[1] = valueMatrix[1,i],...
                     propsArray[k] = valueMatrix[k, i] />)

   }

   return array;

}

or some better and more efficient way of doing this. Thank you.

Added: Why is this more efficient? I could input my json file data arrays instead of individual entry. Also it helps with my code clarity because I use this so often. No one wants a bunch of for loops and perhaps for loops inside another for loop in a document.

about 4 years ago · Juan Pablo Isaza
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