I have tried to loop over items of an array but I am missing some typing for my components in TypeScript. I have tried Card<any or Card<IProps> with the interface being defined below (not being used below).
This is the error I've gotten so far I get this error.
Type '{ key: number; card: { name: string; image: string; id: number; }; }' is not assignable to type 'IntrinsicAttributes & { children?: ReactNode; }'. Property 'card' does not exist on type 'IntrinsicAttributes & { children?: ReactNode; }'.
I am curious to learn what it is exactly that I am missing here?
const cards = [
{
name: "a",
image: "red",
id: 1
},
{
name: "b",
image: "blue",
id: 2
},
{
name: "c",
image: "green",
id: 3
}
];
interface IProps {
card: {
name: string;
image: string;
id: number;
};
key: string;
}
...(Stateless component logic here)...
const renderCards = () => {
return cards.map(card => {
return <Card key={card.id} card={card} />;
});
};
return (
<div>
<CardContainer>{renderCards()}</CardContainer>
</div>
);