In my frontend Reactjs app, I upload multiple images at the same time and save the urls in an array. When trying to loop an array which contains url to display on website, it shows each image in a separate box (which is good). However, when I click on a single image, it renders all the image urls in the array as per console log.
When I click a single image this shows up in console log:
http://192.168.22.124:3000/source/5102018114022AM-pexels-photo.jpg http://192.168.22.124:3000/source/5102018114022AM-redhat.jpg
handleClick() {
this.setState({ isToggleOn: !this.state.isToggleOn})
}
render() {
const { name, fileExt, pic } = this.state;
var img = [];
for (var i = 0; i < pic.length; i++) {
console.log(pic[i]);
img.push(<a style={{width: 200, height: 250}} key={i} className={'tc ' + change + ' dib br3 ma2 pa2 grow bw2 shadow-5'} onClick={this.handleClick}>
<div key={i}>
<img style={{width: 175, height: 175}} className='tc br3' alt='robots' key={i} src={`${pic[i]}`}/>
</div>
</a>)
};
return (
isToggleOn && fileExt !== 'mp4' ?
<div>
{ img }
</div>