So my image slider shows what looks like a refresh for the first 4 clicks of my image slider.
So, if you check my codesandbox and click the next
or prev
button all the way through the 4 images, you'll see a slight flash with a red background.
Here is my prototype https://codesandbox.io/s/sad-satoshi-l38sg?file=/src/Hero.js
The refresh/flash stops right after you get through the last image and it essentially resets. I only have 4 items in my data array that I am mapping through, so once you click through all the images, it seems to stop refreshing.
How do I get rid of this refresh everytime I click through my images?
I tried adding e.preventDefault() into the body of my next and prev slide button functions, but that didn't stop it.
Also, what is causing this flash/refresh for the first four clicks? If you refresh the page and click through the images, it does it everytime for the first 4 images
This is what my next and prev functions look like
const nextSlide = () => {
if (timeout.current) {
clearTimeout(timeout.current);
}
setCurrent(current === length - 1 ? 0 : current + 1);
console.log(current);
};
const prevSlide = () => {
if (timeout.current) {
clearTimeout(timeout.current);
}
setCurrent(current === 0 ? length - 1 : current - 1);
console.log(current);
};