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

248
Vistas
Can I store a component in a variable and push children to it after it has been created?

Lets say that I have this component:

const Test = ({ children, ...rest }) => {
    return <>{children}</>
};

export default Test;

I am wondering if it is possible to create a variable that holds the component like this:

const test = <Test></Test>;

And then loop over some data and push children to the test variable on every iteration.

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

0

if you don't have the data yet, then all you have to do is conditionally render your component when you do have the data.

{ data ? (<Test>{data.map(...)}</Test>) : <SomeOtherComponent /> /* or null */}

or

{ data ? <>{data.map((x) => <Test>{x}</Test>)}</> : <SomeOtherComponent /> /* or null */}

depending on what you want achieve, i didn't fully understand your question

i.e. if you have the data you need, render the component, rendering the children as you see fit, otherwise render some other component (or null, to render nothing)

about 4 years ago · Juan Pablo Isaza Denunciar

0

Yeap, try that pattern:

const test = (children) => <Test>{children}</Test>;

and usage

<>
{[1,2,3].map(el=>test(el))}
</>

[Edited]

const TestComp = ({children}) => <Test>{children}</Test>;

<>
{[1,2,3].map(el=>(<TestComp>{el}</TestComp>))}
</>
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