I want to map two images per list item.
I have a slider, that will show two slides per view, so I want it to show 4 images per view.
currently, its just showing the same image which is what I expected it to do, I just don't know how to map two different images per list item.
How would I go about mapping this array so that each list item has two different images?
SliderComponent.js
import React, { useState, useEffect, useRef } from "react";
import { IonGrid, IonRow, IonCol } from '@ionic/react';
import { Storage } from "aws-amplify";
import Slider from "react-slick";
import "slick-carousel/slick/slick.css";
const SliderComponent = (props) => {
const { job } = props;
const [images, setImages] = useState([]);
const settings = {
infinite: false,
slidesToShow: 2,
slidesToScroll: 2,
speed: 500,
rows: 1,
initialSlide: 0,
autoHeight: false,
focusOnSelect: true,
arrows: false,
};
useEffect(() => {
async function onLoad() {
try {
const downloadedImage = await getImage(job);
setImages(downloadedImage);
} catch (e) {
alert(e);
}
}
onLoad();
}, []);
async function getImage(jobID) {
const imageURL = await Storage.list(`${jobID}/completed/`);
let imagesToDownload = imageURL
let imagesAsArray = [];
for (let i = 0; i < imagesToDownload.length; i++) {
const imagesDownloaded = await getURLFromS3(imagesToDownload[i]);
imagesAsArray.push(imagesDownloaded)
}
return imagesAsArray
}
async function getURLFromS3(fileToDownload) {
const result = await Storage.get(fileToDownload.key)
return result;
}
return (
<div>
<IonGrid>
<IonRow style={{ justifyContent: 'center' }}>
<IonCol sizeXs="12" sizeSm="12" sizeMd="10" sizeLg="6" sizeXl="4" >
<Slider asNavFor={nav1} ref={slider => (slider2.current = slider)} {...viewSettings}>
{images.map((image, i) =>
<ul>
<li><img key={i} src={image} /></li> /// First image
<li><img key={i} src={image} /></li> /// Second image
</ul>
)}
</Slider>
</IonCol>
</IonRow>
</IonGrid>
</div>
)
}
export default SliderComponent;
props.job page
import React, { useState, useEffect } from "react";
import { withRouter } from 'react-router-dom';
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar, IonGrid, IonCol, IonRow, } from '@ionic/react';
import { API, Auth } from "aws-amplify";
import SliderComponent from '../components/sliderComponent.js'
function propertyInfo(props) {
return (
<IonPage>
<IonHeader>
<IonToolbar>
<IonTitle>prop address</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
<SliderComponent job={props.match.params.id} />
</IonContent>
</IonPage>
);
}
export default withRouter(propertyInfo);
props.jobcode?