Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!