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

135
Vistas
How to get the list of all props of all compositional hierarchy in React?

Let's say I have multiple layers of composition:

const ComponentA = ({ firstProp, secondProp }) => {
    reutrn <div>Component A</div>
}

const ComponentB = ({ thirdProp, fourthProp }) => {
    reutrn <ComponentA
         firstProp='first prop'
         secondProp='second prop'
    />
}

const ComponentC = ({ fifthProp }) => {
    return <ComponentB
         thirdProp='third prop'
         fourthProp='fourth prop'
    />
}

Now I have given an instance of ComponentC and I want to access all of the props in the compositional hierarchy.

How can I do that?

Update

To clarify more, I'm talking about reflection.

I have been given an instance of ComponentC and I want to find out its props using componentCInstance.props and then find out the props of the ComponentB from that componentCInstance etc.

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

0

Short answer: you can't access all props at Component C this way.

Solution 1: If Component C is the source of all props, you need to define them there, and pass down the component tree

Solution 2: If your hierarchy is too long, consider using Context (https://reactjs.org/docs/hooks-reference.html#usecontext).

Solution 3: If your props are independent from Component C and are part of application state, consider using a state management tool (for example https://redux.js.org/)

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