Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMun7 committed Oct 2, 2024
1 parent 2abb927 commit a1dfffc
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions new-dti-website/components/courses/TestimonialSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@ export default function TestimonialSlider({ testimonials }: TestimonialSliderPro
const [scrollAtEnd, setScrollAtEnd] = useState(false);

useEffect(() => {
// Ensure the return value is always consistent (cleanup function)
if (testimonials.length === 0 || scrollAtEnd) return;

const slider = sliderRef.current;
if (!slider || isScrolling) return;

// Return early if there are no testimonials or if we've reached the end
if (!slider || testimonials.length === 0 || scrollAtEnd || isScrolling) {
return undefined; // Return `undefined` explicitly to satisfy consistent-return rule
}

const scrollInterval = setInterval(() => {
const maxScrollLeft = slider.scrollWidth - slider.clientWidth;

if (slider.scrollLeft < maxScrollLeft) {
slider.scrollLeft += 2; // Adjust the scroll speed as needed
} else {
setScrollAtEnd(true); // Stop scrolling when the end is reached :)
// slider.scrollLeft = 0 if you want it to restart at the beginning
setScrollAtEnd(true); // Stop scrolling when the end is reached
// slider.scrollLeft = 0 if we want to start from the begnning :)
}
}, 25); // Adjust the interval as needed for smoother/faster scrolling

return () => clearInterval(scrollInterval); // Cleanup function
// Return the cleanup function
return () => {
clearInterval(scrollInterval);
};
}, [testimonials, isScrolling, scrollAtEnd]);

const handleMouseEnter = () => {
Expand Down

0 comments on commit a1dfffc

Please sign in to comment.