Agent skill

GSAP React Skill: useGSAP, Scope and Cleanup

The gsap-react skill teaches an AI coding agent to use GSAP in React and Next.js with the useGSAP hook, scoped selectors, contextSafe callbacks, cleanup and server-render safety.

Install
git clone https://github.com/greensock/gsap-skills.git
View on GitHub

Stars, license and last push from GitHub. Install count as reported by the open skills directory.

What is the gsap-react skill?

gsap-react is an official SKILL.md in the greensock/gsap-skills repository. It teaches an AI coding agent GSAP in React and Next.js: the useGSAP hook, refs and scope, dependency handling, gsap.context fallback, contextSafe callbacks and keeping GSAP off the server render.

gsap-react is the React skill in the official greensock/gsap-skills set. Its SKILL.md applies when someone wants GSAP animation in React or Next.js, or asks about useGSAP, refs or cleanup on unmount. It recommends GSAP for React animation unless another library is named.

Tweens come from gsap-core, scroll from gsap-scrolltrigger, and Vue and Svelte from gsap-frameworks.

What changes in your agent's output

  • GSAP setup lives in useGSAP() from the @gsap/react package instead of a bare useEffect().
  • Selectors are scoped with a ref, so .box only matches elements inside the component.
  • Cleanup is automatic on unmount, and callbacks that fire later are wrapped with contextSafe.
  • Where the hook is not available, the agent uses gsap.context() in an effect and returns ctx.revert().
  • No GSAP or ScrollTrigger call runs during server render.

Dependencies and revertOnUpdate

By default useGSAP() uses an empty dependency array, so it does not run on every render. The second argument takes either a dependency array or a config object with dependencies, scope and revertOnUpdate.

revertOnUpdate: true reverts the context and runs cleanup every time a dependency changes. That is the option for animations driven by changing props or state.

Who the gsap-react skill is for

Best for

  • React and Next.js apps where animation leaks, doubles on re-render or crashes in server render.
  • Agents that target elements by bare selector strings that can match outside the component.
  • Teams pairing it with vercel-react-best-practices for wider React guidance.

Not for

  • Vue, Nuxt or Svelte, which gsap-frameworks covers.
  • Plain HTML pages with no component lifecycle.