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

106
Views
Passing components as prop in React and calling them as JSX tags

Lets say I have a wrapper component:

// wrapper that renders component passed as a prop
const Component = (childrenComponent) => <div>{childrenComponent}</div>

What I'd like to do is to invoke Component within some page, like:

import React from 'react'

const Page = () => {
  const ChildrenComponent = () => <div>Children Component</div>
  return <Component childrenComponent={ChildrenComponent} />
}

This will work well. My question is, given that prop names should be lowerCase, how can I change wrapper component code to be able to invoke ChildrenComponent in a JSX way (, instead of inline {childrenComponent}, while satisfying the requirement to name react components in PascalCase:

// this will not work
const Component = (childrenComponent) => <div><childrenComponent /></div>
// this will work but the prop name isn't camelCase
const Component = (ChildrenComponent) => <div><ChildrenComponent /></div>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can setup Component like this:

const Component = props => {
   return (
   <div>{props.children}</div>
   )
}

Using Component:

<Component>
    <ChildrenComponent/>
</Component>

More reading material from the docs

about 4 years ago · Juan Pablo Isaza Report

0

You can use cloneElement as follows:

const Component = (children, ...props) => {
  const clonedChild = cloneElement(children(), props)
  return <>{clonedChild}</>
}

You need to wrap the returning result into a fragment.

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!