In this react tutorial, the author uses a snippet of code, starting on line 61:
const List = (props) => (
<ul>
{props.list.map((item) => (
<Item key={item.objectID} item={item} />
))}
</ul>
);
This function is called from within the const, App, <List list={stories} /> on line 35. And lastly, stories is an object:
const stories = [
{
title: 'React',
url: 'https://reactjs.org/',
author: 'Jordan Walke',
num_comments: 3,
points: 4,
objectID: 0,
},
{
title: 'Redux',
url: 'https://redux.js.org/',
author: 'Dan Abramov, Andrew Clark',
num_comments: 2,
points: 5,
objectID: 1,
},
];
I'm confused regarding line 61, specifically the code props.list.map. From the object, stories, there is no list attribute. However, in line 35, <List list={stories} /> seems to imply that stories will be referenced by the key, list.
My questions are:
- What's going on here?
- Why would this extra complexity be beneficial (globally speaking beyond the context of this code)?