diff --git a/client/src/components/photostory/Carousel.js b/client/src/components/photostory/Carousel.js index dd6c89d3..ad8e7d58 100644 --- a/client/src/components/photostory/Carousel.js +++ b/client/src/components/photostory/Carousel.js @@ -13,19 +13,15 @@ const Carousel = ({ content }) => { const classes = useStyles(); const length = content.length; - const [left, setLeft] = useState(length - 1); const [current, setCurrent] = useState(0); - const [right, setRight] = useState(1); + const left = current === 0 ? length - 1 : current - 1; + const right = current === length - 1 ? 0 : current + 1; const nextSlide = () => { - setLeft(left === length - 1 ? 0 : left + 1); setCurrent(current === length - 1 ? 0 : current + 1); - setRight(right === length - 1 ? 0 : right + 1); }; const prevSlide = () => { - setLeft(left === 0 ? length - 1 : left - 1); setCurrent(current === 0 ? length - 1 : current - 1); - setRight(right === 0 ? length - 1 : right - 1); }; if (!Array.isArray(content) || content.length <= 0) {