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

90
Vistas
How can I render children inside a component that does not render children?

I have an imported React component that I have no control over and I want to inject? content into it. How can I do that?

Pseudocode:

A component might look like this:

export const Component = ( props ) => {
    const { children } = props
    
    return (
        <div className="some-component">
          <div className="header">
            <h2>Component header</h2>
            // ideally, there would be something like {props.headerContent} here
            // How can I add additional content here ?
          </div>
          <div className="body">
            {children}
          </div>
        </div>

    );
};

Usage

import { SomeComponent } from 'some-components-on-npm';


export const MyComponent = () => {
        
    return (
        <SomeComponent
         headerContent="Obviously won't work"
        >
          <div>Body content</div>
        </SomeComponent>

    );
};

EDIT: If it's any easier, I'd be content with injecting content at the root level of the component. It doesn't need to be nested as the example suggests

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

0

As I understand, what you want is a Higher Order Component (HOC). A HOC is a function that takes a component and returns a new component. You can create/manipulate/fetch data inside a HOC and the data can be sent down to the received component.

const Wrapper = Component => ({ ...props }) => (
  const data = axios.get()
  // manipulate data
  // add redux store
  // ...
  <Component {...props} data={data}/>
);

And you can use it like this:

const WrappedComponent = Wrapper(Component);

You can read more about HOCs in the official react documentation

about 4 years ago · Juan Pablo Isaza Denunciar

0

You cant give a component props as the component itself wont do anything with them.

The simplest solution that might work but probably wont is to wrap the component in another component and then put both your injected child and the component itself in as siblings although im guessing this wont work

<div>
<YourHeader />
<SomeComponent />
</div>

next option is if the component itself is open source you can make a pull request and/or a fork.

Last option is to rewrite the component locally.

Either way though if you want the component to use the props you send it you will need to edit the component itself and react component can't be extended in that way.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Whenever you need access to a component that is imported from a third-party library, just render the component in the browser and then inspect the elements in that component with dev tools. Then use CSS selectors to access those elements, and change their content or style as you wish. Let's say you put the Component in a div with the id of container1 and in the component, you will find 2 divs. Inside the inner div is where you would like to put your content. this would be the code:

const myContent = "This is the content to be put in the component"
document.getElementById("container1").querySelector("div").querySelector("div").innerHTML = myContent
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