So when im on the last item and i click next it will move to next item but wont move the scrollbar back to the beginning unless if I hit next again but then the index is now on the second item not the first.
const nextSlide = () => {
if (current === length - 1) {
setCurrent(0);
listRef.current.scrollIntoView({
behaviour: "smooth",
block: "nearest",
inline: "center",
});
} else {
setCurrent(current + 1);
listRef.current.scrollIntoView({
behaviour: "smooth",
block: "nearest",
inline: "center",
});
}
};
here is the codebox: https://codesandbox.io/s/boring-sea-bfds7?file=/src/App.js