import { useEffect, useRef } from "react" export default function SwipeableViews( { className = "", index, onChangeIndex, ...rootProps }: { index: number, onChangeIndex: (index: number) => void } & React.HTMLProps ) { const containerRef = useRef(null) const scrollTimeout = useRef() useEffect(() => { containerRef.current?.children[index]?.scrollIntoView({ behavior: "smooth" }) }, [index]) return (
{ if (scrollTimeout.current) clearTimeout(scrollTimeout.current) scrollTimeout.current = window.setTimeout(() => { const pageWidth = currentTarget.scrollWidth / currentTarget.children.length onChangeIndex(Math.round(currentTarget.scrollLeft / pageWidth)) }, 100) }} /> ) }