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

142
Vistas
How to render a component that is passed as a prop in React?

I am tying to render my pages by using a loop instead of writing each of them separately. I made this array to store the information for my pages.

const pages = [
  { title: "Translate", url: "/translate", component: TranslatePage },
  { title: "Study", url: "/study", component: StudyPage },
  { title: "About", url: "/about", component: AboutPage },
  { title: "Home", url: "/", component: HomePage },
  { title: "Terms", url: "/study/terms", component: TermsPage },
];

For each page, I need to render it in this format:

        <Route
          path="/study"
          exact
          element={
            <StudyPage
              getDocuments={getDocuments}
              collectionRef={collectionRef}
              docs={docs}
            />
          }
        />

How can I render each page using currentPage.component to write the element part of the Route component? For each Component in my page array, I need to get

element={<ComponentReadFromPagesArray 
    getDocuments={getDocuments}
    collectionRef={collectionRef}
    docs={docs}
/>}

but I don't know how to pull the component from the array and then pass it in to element as its own component with props

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

0

If I understand your question correctly, it'd be like this:

const routes = pages.map(({component: Page, url: path}) => {
  const element = (<Page {...{collectionRef, docs, getDocuments}} />);
  return (<Route {...{element, exact: true, path}} />);
});
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