I want a set up an Array of items, that have various properties, as a Prop on my component.
I’m trying to pass an array of items with different properties to a component, so, let’s say that this is my array of objects:
` let recepies = [
{
name: "A Name",
imageURL: "V",
difficulty: "C",
time: 12,
categories: "c",
},
{
name: "aa",
imageURL: "bb",
difficulty: "cc",
tieme: 13,
categories: "c",
}]
`
When I get to my Component, how do I define the Props?
I guessed
`interface Props {
recepies: Object[];}
`should work, but when I get to:
return(recepies.forEach(function (recipe) {
<RecepieCard
name={recipe.namme}
I get that the property doesn’t exist on the object. How should I go about doing this?
2
Answers
you shod define and assign type to your object like this
and assign your object
then use them on your component and Be careful type correct property of your object
name no namme
The
interface
is only the specififing the structure of the props.You have to pass the Props to your component.
https://react.dev/learn/passing-props-to-a-component