← All articles

Animating a Next.js site with GSAP without the headaches

GSAPNext.js

GSAP and React can get along nicely, but only if you respect the component lifecycle. Most bugs come from animations that outlive the elements they target.

Use a scoped context

The useGSAP hook from @gsap/react wraps gsap.context() and reverts every tween and ScrollTrigger when the component unmounts or its dependencies change.

useGSAP(() => {
  gsap.from(".card", {
    y: 40,
    opacity: 0,
    stagger: 0.1,
    scrollTrigger: { trigger: ".cards", start: "top 80%" },
  });
}, { scope: container, dependencies: [pathname] });

Respect reduced motion

Motion should enhance a page, never block it. Always provide a calm fallback.

Wrap animations in gsap.matchMedia() so users who prefer reduced motion see content immediately.