Map data in react bootstrap card component, using Map method
To map data in a React Bootstrap card component, you can use the JavaScript map()
function to dynamically render an array of data into multiple Card
components. Below is an example:
Explanation:
Data Array:
Thedata
array contains objects with information likeid
,title
,text
, andimgUrl
.Bootstrap Grid:
Row
andCol
components from React Bootstrap are used for responsive layout.- The
xs
,sm
, andmd
props define the number of columns on different screen sizes.
Mapping Data:
- The
map()
function iterates over thedata
array and creates aCard
for each object. - The
key
prop is added to eachCol
to ensure unique identification of elements.
- The
Card Components:
- Each
Card
displays an image, title, and text dynamically based on the array data.
- Each
Styling:
Theg-4
class adds spacing between the cards.
Output:
This code will render a responsive grid of cards, each populated with data from the data
array. You can customize the content and styles as needed.