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

110
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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