gsap-react

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

Updated Jun 17, 2026
One-click install
npx skills add https://github.com/KKChen666/TongXiao --skill gsap-react-kkchen666
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: gsap-react
Source: https://github.com/KKChen666/TongXiao/tree/main/.opencode/skills/gsap-react
Command: npx skills add https://github.com/KKChen666/TongXiao --skill gsap-react-kkchen666

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 break during server-side rendering because developers skip cleanup or misuse selectors. This Skill provides the correct patterns for integrating GSAP with React and Next.js so animations are scoped, reverted on unmount, and client-only. ## 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 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: When building a Next.js landing page with staggered entrance animations, apply this Skill to scope selectors to a container ref, register useGSAP, and avoid SSR errors and detached-node updates. ## Quick Start Ask the AI to add a GSAP fade-in animation to a React component using the useGSAP hook with a scoped container ref and proper 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 animations in React components?

Use the useGSAP hook from @gsap/react instead of useEffect. Register it with gsap.registerPlugin(useGSAP), pass a container ref as scope, and write your tweens inside the hook; cleanup runs automatically on unmount.

What is the difference between useGSAP and gsap.context in useEffect?

useGSAP handles cleanup, scoping, and contextSafe callbacks automatically. gsap.context() inside useEffect is the fallback when @gsap/react is unavailable, but you must manually return ctx.revert() in the cleanup function.

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

GSAP runs only in the browser, so never call gsap or ScrollTrigger during SSR. Keep all GSAP code inside useGSAP or useEffect so it executes client-side only; dynamic imports inside effects are an option for bundle control.

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

Leaks happen when cleanup is skipped or animations are created in event handlers outside the GSAP context. Always revert the context on unmount and wrap late-created animations in contextSafe so they are tracked and reverted.

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(). Selector strings like .box then match only elements inside that container, preventing cross-component targeting.