gsap-react

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

Updated Aug 12, 2026
One-click install
npx skills add https://github.com/brunoolf/frontend-craft --skill gsap-react-brunoolf
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: gsap-react
Source: https://github.com/brunoolf/frontend-craft/tree/main/skills/gsap-react
Command: npx skills add https://github.com/brunoolf/frontend-craft --skill gsap-react-brunoolf

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires gsap, @gsap/react.

What problem does it solve? GSAP animations in React often leak memory, target wrong elements across re-renders, or crash during server-side rendering. This Skill provides the correct patterns for integrating GSAP with React and Next.js so animations are scoped, cleaned up on unmount, and never run during SSR. ## Core Features & Use Cases - useGSAP Hook Patterns: Replaces useEffect with the useGSAP hook from @gsap/react, including scope, dependency arrays, and revertOnUpdate configuration. - gsap.context() Fallback: Shows how to use gsap.context() inside useEffect with mandatory ctx.revert() cleanup when @gsap/react is unavailable. - Context-Safe Callbacks: Wraps event-handler animations in contextSafe so late-created tweens are still reverted on unmount. - Use Case: You are building a Next.js landing page and want staggered entrance animations on a component. The Skill guides you to register useGSAP, pass a container ref as scope, and let cleanup run automatically without SSR errors. ## Quick Start Ask the AI to add a GSAP fade-in animation to a React component using the useGSAP hook with proper scoping and cleanup.

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 in a React component?▼

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

Should I use useGSAP or useEffect for GSAP animations?▼

Prefer the useGSAP hook from @gsap/react because it provides automatic cleanup, scoping, and contextSafe callbacks. Use useEffect with gsap.context() only when @gsap/react is unavailable, and always call ctx.revert() in the cleanup function.

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 code inside useGSAP or useEffect so it runs client-side only, and consider dynamic imports if bundle size is a concern.

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 revert the context on unmount.

How do I scope GSAP selectors to a single React component?▼

Pass a ref or element as the scope option in useGSAP or as the second argument to gsap.context(). This limits selectors like .box to that component's subtree so they never match elements elsewhere on the page.