gsap-react

Implements GSAP animations in React using useGSAP, refs, and context cleanup.

1|Updated Aug 20, 2023
One-click install
npx skills add https://github.com/imanlangaran/mini-projects --skill gsap-react-imanlangaran
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: gsap-react
Source: https://github.com/imanlangaran/mini-projects/tree/main/building-sell/.claude/skills/gsap-react
Command: npx skills add https://github.com/imanlangaran/mini-projects --skill gsap-react-imanlangaran

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires gsap, @gsap/react.

What problem does it solve? GSAP animations in React often cause memory leaks, stale animations on unmounted components, and SSR errors when developers use plain useEffect without proper cleanup. 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 automatic cleanup, scoped selectors, and contextSafe callbacks using @gsap/react. - gsap.context() Fallback: Use gsap.context() inside useEffect with ctx.revert() cleanup when @gsap/react is unavailable. - SSR Safety: Keep all GSAP and ScrollTrigger code client-only to avoid server-side rendering errors in Next.js. - Use Case: You are building a Next.js landing page and want staggered entrance animations that clean up properly on route change. This Skill gives you the exact useGSAP setup with scope, dependencies, and revertOnUpdate configuration. ## Quick Start Ask the AI to add a GSAP fade-in animation to a React component using the useGSAP hook with proper cleanup and scoping.

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 React?

Install gsap and @gsap/react, register the useGSAP plugin, then call useGSAP with your animation code and a scope ref. The hook handles cleanup automatically on unmount, replacing manual useEffect and gsap.context() boilerplate.

What is the useGSAP hook in @gsap/react?

useGSAP is a React hook from @gsap/react that wraps GSAP setup in a managed context. It accepts a callback plus an optional config object with dependencies, scope, and revertOnUpdate, and automatically reverts animations on unmount.

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

GSAP runs only in the browser and must not execute during SSR. Place all GSAP and ScrollTrigger code inside useGSAP or useEffect so it runs client-side only; dynamic imports inside effects are an option for bundle control.

Why do my GSAP animations leak or run on unmounted components?

Leaks happen when animations are created outside the GSAP context, such as in event handlers, or when ctx.revert() is missing from the effect cleanup. Wrap late-created animations in contextSafe and always return a cleanup that reverts the context.

Should I use useGSAP or useEffect with gsap.context?

Prefer useGSAP from @gsap/react since it handles cleanup, scoping, and contextSafe callbacks automatically. Use gsap.context() inside useEffect only when @gsap/react is unavailable, and always call ctx.revert() in the cleanup function.