Problem
Build an image carousel for a marketing hero section.
Requirements
- Show one slide at a time with prev/next controls and dot indicators.
- Autoplay every 4s; pause on hover and when tab is hidden (
document.visibilityState). - Infinite loop (last → first).
- (Bonus) touch swipe, lazy-load off-screen images, respect
prefers-reduced-motion.
Hints / Approach
- Index-based state
% slides.lengthfor looping. useEffect+setIntervalwith cleanup; clear on pause.visibilitychangelistener to pause autoplay in background tabs.