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

115
Vistas
How to Object destructuring in child component in REACT

What is the problem with Object destructuring in REACT here? Check the CODEPEN HERE The same destructuring works outside React. How can I send object as an argument and have a parameterized destructure in the child component?

const MyComponent= ({name,age})=> { 
    return (
      <div>
        <h1> HI THERE I M {name}</h1>
      </div>
    );
}  


function App() {

  let person = { name: "ALEN", age : 40};
  return (
    <div>
      <MyComponent person={person} />
    </div>
  );
}

ReactDOM.render(<App />, document.querySelector("#root"));
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

React will pass an object down to MyComponent that looks like this:

{ person: { name: "ALEN", age: 40 } }

Because you specify the properties name and age in your object destructuring and not person, it will be undefined.

You can declare the function like this:

const MyComponent = ({ person: { name,age } }) => { 
    return (
      <div>
        <h1> HI THERE I M {name}</h1>
      </div>
    );
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You are getting person in props, not name and age, you can follow like this.

First destruct person from props then destruct name and age from person.

const MyComponent = ({ person }) => {
const { name, age } = person;
  return (
    <div>
      <h1> HI THERE I M {name}</h1>
    </div>
  );
};
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