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

126
Vistas
Passing HTML element as a prop with other props

I have a component where I need to pass a HTML element as a prop to another element

const MyText = () => {
     return (
          <>
               <h1>Sample heading</h1>
          </>
     )
}

return (
    <div>
      <MyComponent Text={MyText} onClose={() => setShow(false)} show={show} />
    </div>
  );

MyComponent.js

export default function MyComponent(props) {
  return (
    <>
    {props.Text}
    </>
  );
}

Issue: I'm not getting anything rendered on the screen. Am I missing something here?

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

0

There are two ways.

Option 1: Passing a component type (or class if you are coming from OOP background)

const MyText = () => {
  return (
    <>
      <h1>Sample heading</h1>
    </>
  )
}

return (
  <div>
    <MyComponent Text={MyText} onClose={() => setShow(false)} show={show} />
  </div>
);


const MyComponent = ({ Text }) => {
  return (
    <>
      <Text />
    </>
  );
}

Option 2: Passing a component (or instance if you are coming from OOP background)

const MyText = () => {
  return (
    <>
      <h1>Sample heading</h1>
    </>
  )
}

return (
  <div>
    <MyComponent text={<MyText />} onClose={() => setShow(false)} show={show} />
  </div>
);


const MyComponent = ({ text }) => {
  return (
    <>
      {text}
    </>
  );
}
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