Here is my code:
import React,{ useState } from 'react';
import { Button, Card, Carousel } from 'react-bootstrap';
export default function L() {
const [index, setIndex] = useState(0);
let updateIndex = () => {
let temp;
if (index === 2) {
temp = 0;
} else {
temp = index + 1;
}
setIndex(temp);
}
return (
<Card className="p-1 vh-100 vw-100" variant="dark">
<Card.Header className="border border-dark d-flex flex-row justify-content-center mb-1 rounded-3">
Header
</Card.Header>
<Card.Body className="border border-dark d-flex flex-grow-1 m-0 p-1 rounded-3">
<Carousel
activeIndex={index}
className="d-flex flex-grow-1 m-0 p-0 rounded-3"
controls={false}
interval={10000}
indicators={false}
nextIcon={null} nextLabel={null}
prevIcon={null} prevLabel={null}>
<Carousel.Item className="border border-dark h-100 m-0 p-0 rounded-3">
1
</Carousel.Item>
<Carousel.Item className="border border-dark h-100 m-0 p-0 rounded-3">
2
</Carousel.Item>
<Carousel.Item className="border border-dark h-100 m-0 p-0 rounded-3">
3
</Carousel.Item>
</Carousel>
</Card.Body>
<Card.Footer className="border border-dark d-flex flex-row justify-content-around mt-1 rounded-3">
<Button onClick={updateIndex}>Go</Button>
</Card.Footer>
</Card>
)
}
The code works fine except when sliding from the last carousel item to the first carousel item. When sliding from the first item to the second item, the sliding direction is right to left. However, when sliding from the last item from the first item, the sliding direction is left to right. Is it possible to unify the sliding direction whatever any item transitions?