I am trying to display five card components in one row. My goal is to change the no of card elements dynamically for different screen-size. To achieve this I passed a condition in JSX. Here is a sample code
import React from 'react';
function Layout () {
const data = [
{
id: 1,
title: "Test-1"
},
{
id: 2,
title: "Test-2"
},
{
id: 3,
title: "Test-3"
},
{
id: 4,
title: "Test-4"
},
{
id: 5,
title: "Test-5"
},
{
id: 6,
title: "Test-6"
},
{
id: 7,
title: "Test-7"
},
//more data is here
]
const Card = () => {
const cssCard = {
width: "175px",
height: "225px",
padding: "15px",
cursor: "pointer",
borderRadius: "3px",
border: "1px solid black"
}
return(
<>
{
data.map((item, index) =>
<ul className='card' key={index} style={cssCard}>
<li> {item.id} </li>
<li> {item.title} </li>
</ul>
)
}
</>
);
}
const cssCardHolder = {
display: "flex",
flexWrap: (((data.length % 5) === 0 || data.length === 0) ? "wrap" : "nowrap"),
gap: "1.5rem 1.5rem"
}
return (
<section className="card--holder" style={cssCardHolder}>
<Card />
</section>
);
}
export default Layout;
Unfortunately flexWrap: (((data.length % 5) === 0 || data.length === 0) ? "wrap" : "nowrap")
flexWrap
property is not working. Yes, it is possible to display by changing the "card--holder" with some width. But I am looking for something to change by applying some conditions. Appreciate any better suggestion/approach.