When you hard code the cards it works well and they in row format, but when i try to iterate through them using the map function, it doesn't work. please help me.
const BodyComponent = (props) => {
const [ restaurants, setRestaurants ] = useState([
{name: "Rolex Guy Entebbe", },
{name: "Cafe Java Victoria Mall", },
{name: "KFC Vicatoria Mall", },
{name: "Niki's Pizzeria", },
{name: "muti Restaurant", },
])
return(
<Container style={{ marginTop: "35px" }}>
<div>
{
restaurants.map(restaurant =>
<Card.Group itemsPerRow={4} stackable>
<CardComponent />
</Card.Group>
)
}
</div>
</Container>
)
}
export default BodyComponent
Looking at the documentation, it looks like you want to map
Card
and not Card.Group
:
return(
<Container style={{ marginTop: "35px" }}>
<div>
<Card.Group itemsPerRow={4} stackable>
{
restaurants.map(restaurant =>
<CardComponent />
)
}
</Card.Group>
</div>
</Container>
);
You also would need (most likely) pass some props to CardComponent
:
<CardComponent restaurant={restaurant} />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.