import React, { useState, useEffect } from 'react';const catFacts = [ "Cats have over 20 muscles that control their ears.", "A group of cats is called a clowder.", "Cats spend 70% of their lives sleeping.", "The first cat in space was a French cat named Felicette in 1963.", "Cats have a third eyelid called the nictitating membrane to protect their eyes.",];const catImages = [ "https://placekitten.com/300/200", "https://placekitten.com/301/200", "https://placekitten.com/302/200", "https://placekitten.com/303/200", "https://placekitten.com/304/200",];const CatApp = () => { const [currentFactIndex, setCurrentFactIndex] = useState(0); const [currentImageIndex, setCurrentImageIndex] = useState(0); const [factAnimation, setFactAnimation] = useState(''); const [imageAnimation, setImageAnimation] = useState(''); useEffect(() => { setFactAnimation('slide-in'); const timer = setTimeout(() => setFactAnimation(''), 500); return () => clearTimeout(timer); }, [currentFactIndex]); useEffect(() => { setImageAnimation('fade-in'); const timer = setTimeout(() => setImageAnimation(''), 500); return () => clearTimeout(timer); }, [currentImageIndex]); const nextFact = () => { setCurrentFactIndex((prevIndex) => (prevIndex + 1) % catFacts.length); }; const nextImage = () => { setCurrentImageIndex((prevIndex) => (prevIndex + 1) % catImages.length); }; return (
{catFacts[currentFactIndex]}