Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!