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

100
Vistas
Is it possible to add props to the nested component using React.cloneElement?

Consider these components:

const Action = (props) => {
    return <div>Action</div>
}

const SpecialAction = (props) => {
    return <Action
        someProp={'someValue'}
    />
}

Now I'm being given an array of components, that are either Action or SpecialAction. And I want to extend them using React.cloneElement.

If I use this code:

const clonedActions = React.Children.toArray(actions)
.map(React.cloneElement(action, {
    additionalProp: 'additional prop value'
})

It won't affect Action components that are nested inside SpecialAction components.

I know I can refactor SpecialAction to pass the rest of the props:

const SpecialAction = ({specialProp1, specialProp2, ...rest}) => {
    return <Action
        {...rest}
        someProp={'someValue'}
    />
}

But I wonder if there is a way for me to not do that? Can I traverse the component hierarchy and add additional props to every Action component that I find?

about 4 years ago · Juan Pablo Isaza
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