In this challenge when we pass an as props, How react component destructure that array and get the items to display?
https://www.freecodecamp.org/learn/front-end-libraries/react/pass-an-array-as-props
<ParentComponent>
<ChildComponent colors={["green", "blue", "red"]} />
</ParentComponent>
In the snippet above, passing the array ["green", "blue", "red"]
to ChildComponent
means that ChildComponent
now have access to that array. And it can be accessed on props.colors
or by destructuring it off props
For example:
const ChildComponent = ({colors}) => <div>{colors[0]}</div> // green
// or
const ChildComponent = (props) => <div>{props.colors[0]}</div> // green