Answer the question
In order to leave comments, you need to log in
How to render an array of objects with only one parameter using map?
I have an array with data that looks something like this:
const products = [
{
id: 1,
title: "Some title",
category: "Category One"
},
{
id: 2,
title: "Some title",
category: "Category One"
},
{
id: 3,
title: "Some title",
category: "Category Two"
},
{
id: 4,
title: "Some title",
category: "Category Two"
}];
const itemList = products.map(item => <ProductCard
key = {item.id}
title = {item.title}
category = {item.category}
/>)
Answer the question
In order to leave comments, you need to log in
Use filter . Or you can place a conditional construct (with the && operator)
const itemList = products.map(item => item.category === "Category Two" && <ProductCard
key = {item.id}
title = {item.title}
category = {item.category}
/>)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question