I'm doing the fullstackopen2021 curriculum put together by Helsinki University
Im a beginner developer and am trying to get comfortable with destructuring, which is a bit confusing to me.
The <App/> component looks like this
const App = () => {
const course = 'Half stack application development',
parts = [
{
name: 'Fundamentals of React',
exercises: 10,
},
{
name: 'Using props to pass data',
exercises: 7,
},
{
name: 'State of a component',
exercises: 14,
}
];
return (
<>
<table>
<Header course={course} />
<Content parts={parts} />
<Total parts={parts} />
</table>
</>
)
}
My <Content/> component looks like this
const Content = ({ parts: [part1, part2, part3] }) => {
// console.log(part1, part3, part2);
return (
<>
<thead>
<tr>
<th>Course Content</th>
<th>Exercises</th>
</tr>
</thead>
<tbody>
<Part part={part1} />
<Part part={part2} />
<Part part={part3} />
</tbody>
</>
)
}
And my component looks like this
const Part = ({ part: { name, exercises } }) => {
return (
<>
<tr>
<th scope={"row"}>{name}</th>
<td align={"right"}>{exercises}</td>
</tr>
</>
)
}
I got my destructuring to work in the <Content/> component but I cant understand why it works in the way I've done it above but when I do this
const Content = ({ parts: {part1, part2, part3} }) => {
//same as above
}
Using {} curly braces like so { parts: {part1, part2, part3} causes the app to break. Why is this incorrect? Why does the other implementation work?