diff --git a/components/content/RotatingWord.tsx b/components/content/RotatingWord.tsx new file mode 100644 index 0000000..58130e8 --- /dev/null +++ b/components/content/RotatingWord.tsx @@ -0,0 +1,41 @@ +"use client"; + +import { useEffect, useState } from "react"; + +type RotatingWordProps = { + items: string[]; + intervalSeconds?: number; +}; + +export default function RotatingWord({ + items, + intervalSeconds = 2.5, +}: RotatingWordProps) { + const [activeIndex, setActiveIndex] = useState(0); + + useEffect(() => { + if (items.length <= 1) return; + const id = setInterval(() => { + setActiveIndex((i) => (i + 1) % items.length); + }, intervalSeconds * 1000); + return () => clearInterval(id); + }, [items.length, intervalSeconds]); + + return ( + + {items.map((word, i) => ( + + {word} + + ))} + + ); +}