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:
Thedataarray contains objects with information likeid,title,text, andimgUrl.Bootstrap Grid:
RowandColcomponents from React Bootstrap are used for responsive layout.- The
xs,sm, andmdprops define the number of columns on different screen sizes.
Mapping Data:
- The
map()function iterates over thedataarray and creates aCardfor each object. - The
keyprop is added to eachColto ensure unique identification of elements.
- The
Card Components:
- Each
Carddisplays an image, title, and text dynamically based on the array data.
- Each
Styling:
Theg-4class 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.