Hey there!
I have created a timeline within the useGSAP hook (React / Next.js), which I want to play or reverse using a button. Unfortunately, only the "normal" playback works.
export default function Home() {
const [animation, setAnimation] = useState(false);
useGSAP(() => {
const timeline = gsap.timeline({ paused: true });
timeline.to(".text", {
fontSize: "50px",
});
if (animation) {
timeline.play();
} else {
timeline.reverse();
}
}, [animation]);
return (
<div>
<div className="text">text!</div>
<button
onClick={() => {
setAnimation(!animation);
}}
>
toggle animation
</button>
</div>
);
}
Have a look (Codesandbox)!