Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda