Skip to content

Commit

Permalink
fix(photostory): optimise the state update in photostory (#444)
Browse files Browse the repository at this point in the history
* fix(photostory): optimise the state update

* fix(photostory): update right side image in carousel
  • Loading branch information
Anish-Sarawgi authored Jul 19, 2023
1 parent 8196cfa commit c1c9338
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions client/src/components/photostory/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c1c9338

Please sign in to comment.