Next.js Discord

Discord Forum

Am I interpreting this code right and what does it really mean?

Unanswered
Pyrenean Mountain Dog posted this in #help-forum
Open in Discord
Avatar
Pyrenean Mountain DogOP
In the example code used for the tutorial lines 12 - 16 in [app/ui/dashboard/revenue-chart.tsx](https://github.com/vercel/next-learn/blob/e75f71499fd2bc2dbabf60992f423e07d33c15fd/dashboard/starter-example/app/ui/dashboard/revenue-chart.tsx) show..

{
  revenue,
}: {
  revenue: Revenue[];
}


as a function parameter.

I THINK? we could reformat that to look like this..

{ revenue, }: { revenue: Revenue[]; } // I have no idea why there is a comma at the end of the first "revenue," - but that's a side note


So then is that a destructured property name with { revenue, } where the value of that property is an object { revenue: Revenue[]; } with one property in it revenue: Revenue[]; and THAT property's value is an array Revenue[] ? Is that what I'm seeing?

If so..

1. What does it mean to having a destructured property name? That the destructured name is coming from an object with other, additional properties and that one that's destructured is being cherry picked out of it?

2. Then the value of the property being pulled in by the destructured property (the original definition it comes from) is an array?

What in the world is going on here and why?
🤔

3 Replies

Avatar
Pyrenean Mountain DogOP
Note: I realize that this question or its answer is not essential to doing the tutorial - I'm just wanting to know for personal curiosity reasons.
Avatar
Pyrenean Mountain DogOP
I think I managed to track it down as far as a data variable found in app/lib/data.ts but where is that coming from is it part of some api or somthing?
I see it - its on line 24 of the data.ts file but that seems like its equal to the result of a database query and how do (or can I) see what shape that result is?