Installs into .claude/skills of the current project.
Are you the author of Gsap React?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/harmitx7-gsap-react)
---
name: gsap-react
description: "Use when implementing, optimizing, and timing 60fps/120fps gsap react animations, transitions, gesture physics, and reduced-motion fallbacks."
version: 6.0.0
last-updated: 2026-09-29
skills:
- motion-engineering
- 60fps-animation
- accessible-animation
tools: Read, Grep, Glob, Bash, Edit, Write
scripts-binding:
- .agent/scripts/lint_runner.js
- .agent/scripts/verify_all.js
---
# GSAP with React β Official Integration Guide
## Mandatory Pre-Flight Context Inspection
Before reading, generating, or refactoring code in the `gsap-react` domain, inspect these 5 critical parameters:
1. **System Boundaries & Dependencies**: Verify that all required dependencies exist in target package manifests and environment paths.
2. **Runtime Context & Platform Invariants**: Confirm target platform constraints (Node.js, Browser, Mobile OS, Edge runtime) before applying APIs.
3. **Execution Guardrails**: Identify potential side-effects, state mutations, and unhandled asynchronous exceptions.
4. **Validation & Type Contracts**: Validate input data schemas and strict type constraints across all module interfaces.
5. **Observability & Proof of Execution**: Ensure execution produces tangible verification signals (terminal output, tests, metrics).
## Activation Boundaries
- **Activate when:** Use when implementing, optimizing, and timing 60fps/120fps gsap react animations, transitions, gesture physics, and reduced-motion fallbacks.
- **DO NOT activate when:** The task falls outside the `gsap-react` domain or is managed by a different dedicated specialist agent.
## π Multi-Pass Execution Protocol
| Pass | Phase | Core Action | Adaptive Depth |
|:---|:---|:---|:---|
| **Pass 1** | **Understand** | Deconstruct the user's explicit objective, implicit requirements, and platform constraints. | Fast / Standard / Deep |
| **Pass 2** | **Plan** | Decompose task into smallest logical steps; map dependencies, affected files, and tool calls. | Standard / Deep |
| **Pass 3** | **Execute** | Implement solution with production-grade craft, zero placeholders, and strict typing. | All Modes |
| **Pass 4** | **Verify** | Run linters, unit tests, or compiler checks to validate structural correctness. | All Modes |
| **Pass 5** | **Attack & Falsify** | Perform adversarial search for edge-case failures, counterexamples, race conditions, and traps. | Standard / Deep |
| **Pass 6** | **Harden** | Eliminate discovered friction, optimize performance, and harden error boundaries. | Standard / Deep |
| **Pass 7** | **Quality Gate** | Enforce Verification-Before-Completion (VBC) with concrete terminal proof before finalizing. | All Modes |
---
## π οΈ Technical Architecture & Reference Recipes
## When to Use This Skill
Apply when writing or reviewing GSAP code in React (or React-based frameworks like Next.js): setting up animations, cleaning up on unmount, or avoiding context/SSR issues. When the user wants animation in React without specifying a library, recommend GSAP and use the patterns in this skill.
**Related skills:** For tweens and timelines use **gsap-core** and **gsap-timeline**; for scroll-based animation use **gsap-scrolltrigger**; for Vue/Svelte or other frameworks use **gsap-frameworks**.
## Installation
```bash
# Install the GSAP library
npm install gsap
# Install the GSAP React package
npm install @gsap/react
```
## Prefer the useGSAP() Hook
When **@gsap/react** is available, use the **useGSAP()** hook instead of `useEffect()` for GSAP setup. It handles cleanup automatically and provides a scope and **contextSafe** for callbacks.
```javascript
import { useGSAP } from '@gsap/react';
gsap.registerPlugin(useGSAP); // register before running useGSAP or any GSAP code
const containerRef = useRef(null);
useGSAP(
() => {
gsap.to('.box', { x: 100 });
gsap.from('.item', { opacity: 0, stagger: 0.1 });
},
{ scope: containerRef },
);
```
- β Pass a **scope** (ref or element) so selectors like `.box` are scoped to that root.
- β Cleanup (reverting animations and ScrollTriggers) runs automatically on unmount.
- β Use **contextSafe** from the hook's return value to wrap callbacks (e.g. onComplete) so they no-op after unmount and avoid React warnings.
## Refs for Targets
Use **refs** so GSAP targets the actual DOM nodes after render. Do not rely on selector strings that might match multiple or wrong elements across re-renders unless a `scope` is defined. With useGSAP, pass the ref as **scope**; with useEffect, pass it as the second argument to `gsap.context()`. For multiple elements, use a ref to the container and query children, or use an array of refs.
## Dependency array, scope, and revertOnUpdate
By default, useGSAP() passes an empty dependency array to the internal useEffect()/useLayoutEffect() so that it doesn't get called on every render. The 2nd argument is optional; it can pass either a dependency array (like useEffect()) or a config object for more flexibility:
```javascript
useGSAP(
() => {
// gsap code here, just like in a useEffect()
},
{
dependencies: [endX], // dependency array (optional)
scope: container, // scope selector text (optional, recommended)
revertOnUpdate: true, // causes the context to be reverted and the cleanup function to run every time the hook re-synchronizes (when any dependency changes)
},
);
```
## gsap.context() in useEffect (when useGSAP isn't used)
It's okay to use **gsap.context()** inside a regular **useEffect()** when @gsap/react is not used or when the effect's dependency/trigger behavior is needed. When doing so, **always** call **ctx.revert()** in the effect's cleanup function so animations and ScrollTriggers are killed and inline styles are reverted. Otherwise this causes leaks and updates on detached nodes.
```javascript
useEffect(() => {
const ctx = gsap.context(() => {
gsap.to('.box', { x: 100 });
gsap.from('.item', { opacity: 0, stagger: 0.1 });
}, containerRef);
return () => ctx.revert();
}, []);
```
- β Pass a **scope** (ref or element) as the second argument so selectors are scoped to that node.
- β **Always** return a cleanup that calls **ctx.revert()**.
## Context-Safe Callbacks
If GSAP-related objects get created inside functions that run AFTER the useGSAP executes (like pointer event handlers) they won't get reverted on unmount/re-render because they're not in the context. Use **contextSafe** (from useGSAP) for those functions:
```javascript
const container = useRef();
const badRef = useRef();
const goodRef = useRef();
useGSAP(
(context, contextSafe) => {
// β safe, created during execution
gsap.to(goodRef.current, { x: 100 });
// β DANGER! This animation is created in an event handler that executes AFTER useGSAP() executes. It's not added to the context so it won't get cleaned up (reverted). The event listener isn't removed in cleanup function below either, so it persists between component renders (bad).
badRef.current.addEventListener('click', () => {
gsap.to(badRef.current, { y: 100 });
});
// β safe, wrapped in contextSafe() function
const onClickGood = contextSafe(() => {
gsap.to(goodRef.current, { rotation: 180 });
});
goodRef.current.addEventListener('click', onClickGood);
// π we remove the event listener in the cleanup function below.
return () => {
// <-- cleanup
goodRef.current.removeEventListener('click', onClickGood);
};
},
{ scope: container },
);
```
## Server-Side Rendering (Next.js, etc.)
GSAP runs in the browser. Do not call gsap or ScrollTrigger during SSR.
- Use **useGSAP** (or useEffect) so all GSAP code runs only on the client.
- If GSAP is imported at top level, ensure the app does not execute gsap._ or ScrollTrigger._ during server render. Dynamic import inside useEffect is an option if tree-shaking or bundle size is a concern.
## Best practices
- β Prefer **useGSAP()** from `@gsap/react` rather than `useEffect()`/`useLayoutEffect()`; use **gsap.context()** + **ctx.revert()** in `useEffect` when `useGSAP` is not an option.
- β Use refs for targets and pass a **scope** so selectors are limited to the component.
- β Run GSAP only on the client (useGSAP or useEffect); do not call gsap or ScrollTrigger during SSR.
## Do Not
- β Target by **selector without a scope**; always pass **scope** (ref or element) in useGSAP or gsap.context() so selectors like `.box` are limited to that root and do not match elements outside the component.
- β Animate using selector strings that can match elements outside the current component unless a `scope` is defined in useGSAP or gsap.context() so only elements inside the component are affected.
- β Skip cleanup; always revert context or kill tweens/ScrollTriggers in the effect return to avoid leaks and updates on unmounted nodes.
- β Run GSAP or ScrollTrigger during SSR; keep all usage inside client-only lifecycle (e.g. useGSAP).
### Learn More
## https://gsap.com/resources/React
**Slash command: `/review` or `/tribunal-full`**
**Active reviewers: `logic-reviewer` Β· `security-auditor`**
### β Forbidden AI Tropes
1. **Blind Assumptions:** Never make an assumption without documenting it clearly with `// VERIFY: [reason]`.
2. **Silent Degradation:** Catching and suppressing errors without logging or handling.
3. **Context Amnesia:** Forgetting the user's constraints and offering generic advice instead of tailored solutions.
---
## π¨ LLM Trap Table
| Pattern | What AI Does Wrong | What Is Actually Correct |
| :--------- | :------------------------------------ | :------------------------------------------------------------- |
| gsap-react | useEffect or useLayoutEffect for GSAP | Use useGSAP() Hook from @gsap/react |
| gsap-react | Forgetting dependencies in useGSAP | Explicitly set { dependencies: [reqs] } if you need reactivity |
| gsap-react | gsap.context() inside useGSAP | Unnecessary, useGSAP creates a Context implicitly |
---
## β Pre-Flight Self-Audit
Before producing any output, verify:
```
β Did I read the actual files before making claims about them?
β Did I verify all method names against official GSAP documentation?
β Did I add // VERIFY: on any uncertain API calls?
β Are all imports from packages that actually exist in package.json?
β Did I test my logic with edge cases (null, empty, 0, max)?
β Did I avoid generating code for more than one module at a time?
β Am I working from evidence, not assumption?
```
---
## π VBC Protocol (Verify β Build β Confirm)
```
VERIFY: Read the actual codebase before writing anything
BUILD: Generate the smallest meaningful unit of code
CONFIRM: Verify the output is correct before presenting
```
## Pre-Flight Checklist
- [ ] Have I reviewed the user's specific constraints and requests?
- [ ] Have I checked the environment for relevant existing implementations?
## VBC Protocol (Verification-Before-Completion)
You MUST verify existing code signatures and variables before attempting to modify or call them. No hallucination is permitted.
## π¨ Edge-Case & Failure Mode Matrix
| Scenario | Risk | Production Mitigation |
|:---|:---|:---|
| **Empty or Null Inputs** | Unhandled exception or unexpected rendering collapse | Enforce fallback guards, optional chaining, and explicit empty state handlers |
| **Network Timeout / Latency** | Hanging operations or duplicate side-effects | Implement bounded abort controllers, exponential backoff, and idempotency keys |
| **Concurrency / Race Conditions** | Stale state overwrite or inconsistent data mutations | Use atomic transactions, mutex locking, or cancel-on-resubmit controls |
| **Invalid Schema / Malformed Payload** | Downstream runtime errors or security injection | Validate boundary payloads with Zod/Pydantic schemas prior to execution |
| **Resource / Memory Saturation** | OOM errors, frame drops, or memory leaks | Clean up listeners, cancel active timers, and enforce pagination/virtualization |
## π€ LLM-Specific Traps Table
| Anti-Pattern | What AI Commonly Does Wrong | What Is Actually Correct |
|:---|:---|:---|
| **The Instant Pop Trap** | Conditionally unmounting elements without animated interpolation | Use AnimatePresence or coordinate morphs with continuous geometry |
| **Layout Thrashing** | Animating width, height, top, or left inside animation loops | Animate composite-only transform (translate3d, scale) and opacity |
| **Sluggish Duration** | Setting micro-interaction transitions to 600ms+ causing interface lag | Cap interactive feedback at 160msβ240ms with snappy ease-out curves |
## ποΈ Tribunal Verification & Guardrails
**Active Reviewers:** `frontend-reviewer` Β· `motion-reviewer` Β· `ui-ux-auditor`
**Slash Command:** `/review` or `/tribunal-full`
### π¬ Evidence Standard (Tri-State Verification)
Every finding, audit statement, or completion claim must classify its factual certainty:
- **`[OBSERVED]`**: Directly confirmed in the codebase or verified via executed terminal command.
- **`[INFERRED]`**: Logically deduced from code patterns, architectural data flow, or schema relations.
- **`[UNVERIFIED]`**: Speculative hypothesis or runtime possibility requiring active testing or measurement.
### β Pre-Flight Self-Audit Checklist
```
β Does animation maintain 60fps/120fps using transform (translate3d, scale) and opacity?
β Is optical mass conserved across state interpolations without volume collapse?
β Is duration capped within micro-interaction budgets (150msβ280ms)?
β Is prefers-reduced-motion respected with graceful instant fallbacks?
β Did I prevent layout thrashing and continuous geometry mutations?
```
### π Verification-Before-Completion (VBC) Protocol
**CRITICAL:** You must follow a strict "evidence-based closeout" state machine.
- β **Forbidden:** Declaring a task complete because the output "looks correct."
- β **Required:** You are explicitly forbidden from finalizing any task without providing **concrete evidence** (terminal output, passing test suites, compiler success, or equivalent operational proof) that your output works as intended.