I’m doing a simple react tutorial and I can’t seem to get my list to render. Here’s my page:
function Item({name, isPacked} ){
return <li className="item">{name}</li>; }
export default function PackingList(){
return(
<section>
<h1>Sally Ride's Packing List</h1>
<ul>
<Item>
isPacked={true}
name="Space suit"
</Item>
<Item>
isPacked={false}
name="Helmet with a golden leaf"
</Item>
<Item>
isPacked={false}
name="Photo of Tam"
</Item>
</ul>
</section>
);}
My index:
div>
<PackingList></PackingList>
</div>
I get an empty list. I put a breakpoint inside Item and both parameters are undefined. What am I doing wrong?
2
Answers
When give props to child component, the props should inside the html tag element.
An example from your question
There are two ways of passing props from parent to child component
1 – destructuring the data
2 – taking from props – inside props goes everything you passed to the component and the children is the one wrapped inside. ‘test’ (in this case, but can be wherever component you want)