I'm well versed with Angular but not React. I want to display images in a row-col layout in such a way that no. of columns should be dynamic while the no. of rows should be adjusted accordingly. That means if the user gives 4(say) images and says that he wants 2(say) columns, then the grid layout should be 2X2. Pretty simple.
I'm setting the state in App.js
state = {
flowerCard: [
{
colCount: 3, // <-------------- this will decide number of columns
tiles: [
{
imageSource: '...',
text: 'White flower',
},
{
imageSource: '...',
text: 'Red flower',
},
{
imageSource: '...',
text: 'Purple flower',
},
{
imageSource: '...',
text: 'Purple flower',
},
],
},
],
};
...
<Card
colCount={this.state.flowerCard[0].colCount}
tiles={this.state.flowerCard[0].tiles}>
</Card>
Card.js
let localTiles = props.tiles;
let colCount = props.colCount;
return (
<div>
{localTiles.map((tile, index) => {
return (
<div>
<Row>
<Col md={4}>
<p>{tile.text}</p>
<Image
className="tile-image"
height={100}
width={300}
src={tile.imageSource}
alt="logo"
/>
</Col>
</Row>
</div>
);
})}
</div>
);
I've done similar thing in Angular using *ngFor. Please help me achieve this in React. I've created one stackblitz for your ease. please pitch in.