gsap-react

Implement GSAP animations in React using the useGSAP hook with scoped selectors and automatic cleanup.

Updated May 23, 2026
One-click install
npx skills add https://github.com/Oatse/CWE-Automation --skill gsap-react-oatse
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: gsap-react
Source: https://github.com/Oatse/CWE-Automation/tree/main/.agents/skills/gsap-react
Command: npx skills add https://github.com/Oatse/CWE-Automation --skill gsap-react-oatse

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires gsap, @gsap/react.

What problem does it solve? GSAP animations in React often leak memory, target wrong elements, or break during SSR because developers skip cleanup, use unscoped selectors, or run GSAP during server rendering. This Skill provides the correct patterns for integrating GSAP with React and Next.js. ## Core Features & Use Cases - useGSAP Hook Patterns: Set up animations with the @gsap/react hook, including scope, dependency arrays, and revertOnUpdate configuration. - Safe Cleanup: Use gsap.context() with ctx.revert() in useEffect, and contextSafe() for callbacks created in event handlers after setup. - SSR Safety: Keep all GSAP and ScrollTrigger code client-only in Next.js and other server-rendered frameworks. - Use Case: When building a Next.js landing page with staggered entrance animations, apply this Skill to scope selectors to a container ref, wrap click-handler tweens in contextSafe, and ensure everything reverts cleanly on unmount. ## Quick Start Set up a GSAP animation in my React component using the useGSAP hook with a scoped container ref and proper cleanup on unmount.

Frequently Asked Questions about gsap-react

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use GSAP animations in a React component?

Use the useGSAP hook from @gsap/react instead of useEffect. Register it with gsap.registerPlugin(useGSAP), then place your GSAP code inside the hook and pass a container ref as the scope so selectors stay within your component.

How do I clean up GSAP animations when a React component unmounts?

The useGSAP hook reverts animations automatically on unmount. If you use gsap.context() inside a regular useEffect instead, always return a cleanup function that calls ctx.revert() to kill tweens and ScrollTriggers and revert inline styles.

Does GSAP work with Next.js server-side rendering?

GSAP runs only in the browser and must not execute during SSR. Keep all gsap and ScrollTrigger calls inside useGSAP or useEffect so they run client-only, and avoid calling GSAP at the top level during server render.

Why do my GSAP animations leak or fire on unmounted components in React?

Leaks happen when animations are created in event handlers after setup, outside the GSAP context, or when cleanup is skipped. Wrap late-created animations in contextSafe() from useGSAP and remove event listeners in the cleanup function.

Should I use useGSAP or useEffect with gsap.context()?

Prefer useGSAP from @gsap/react because it handles cleanup, scope, and contextSafe automatically. Use gsap.context() inside useEffect only when @gsap/react is unavailable or you need specific effect dependency behavior, and always call ctx.revert().