Skip to content

Instantly share code, notes, and snippets.

@karenying
Created June 16, 2020 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karenying/848371ea8cad01eb5689bb552a31f59a to your computer and use it in GitHub Desktop.
Save karenying/848371ea8cad01eb5689bb552a31f59a to your computer and use it in GitHub Desktop.
const [slideIn, setSlideIn] = useState(true);
const [slideDirection, setSlideDirection] = useState('down');
const onArrowClick = (direction) => {
const increment = direction === 'left' ? -1 : 1;
const newIndex = (index + increment + numSlides) % numSlides;
const oppDirection = direction === 'left' ? 'right' : 'left';
setSlideDirection(direction);
setSlideIn(false);
setTimeout(() => {
setIndex(newIndex);
setSlideDirection(oppDirection);
setSlideIn(true);
}, 500);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment