Answer the question
In order to leave comments, you need to log in
How to insert an image into each div element?
Good afternoon. Help me please.
How to transfer an image to a div in turn at each iteration. (img1, img2, img3 etc)?
import React, { Component } from 'react';
import { connect } from 'react-redux';
import img1 from './img/1001.jpg'
import img2 from './img/1002.jpg'
import img3 from './img/1003.jpg'
import img4 from './img/1004.jpg'
import img5 from './img/1005.jpg'
import img6 from './img/1006.jpg'
class ShowBlock extends Component {
render() {
var keys = new Date().getTime();
return (
<div className="ShowBlock">
<div className="row">
{this.props.data.serverData.map((item, index)=>
<div className="col-md-4" key = {index+(2*keys)}>
<div className="block" >
<img src={img1, img2, img3 и тд} />
<div>{item.description}</div>
<div className="col-md-6" id="price">{item.price}</div>
<div className="col-md-6"> <button type="button" class="btn-lg btn btn-success">Buy</button></div>
</div>
</div>
)}
</div>
</div>
);
}
}
Answer the question
In order to leave comments, you need to log in
So?
var imgs = [img1, img2, img3,img4,img5,img6]<img src={imgs[index]+index} />
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question