In the Skill's Own Terms
Official GSAP skill for animation in React and React-based frameworks like Next.js. It pushes the useGSAP() hook from @gsap/react over useEffect() or useLayoutEffect(), registered with gsap.registerPlugin, and requires a scope so selectors such as .box only match elements inside the component.
It covers refs as targets, the hook's optional second argument (a dependency array or a dependencies/scope/revertOnUpdate config object), contextSafe for animations created in pointer handlers after the hook runs, and the gsap.context() plus ctx.revert() fallback for a plain useEffect. It also states the SSR rule: GSAP runs in the browser, so nothing may execute during server render.
What it produces
- A useGSAP block whose animations and ScrollTriggers revert automatically on unmount
- A useEffect body that returns a cleanup calling ctx.revert()
- A contextSafe-wrapped click handler with its event listener removed in the returned cleanup
- Client-only execution, with dynamic import inside useEffect as an option for tree-shaking or bundle size
How It Works
- 01Install Gsap and @gsap/react
Two packages are listed in the installation block: the GSAP library, then the GSAP React package that provides the hook.
- 02Register useGSAP Before Any GSAP Code
The hook is registered as a plugin, and the file says this registration has to happen before running useGSAP or any other GSAP code.
- 03Write the Animation Inside useGSAP with a Scope
Selectors are limited to the component root by passing a ref or element as the scope.
- 04Wrap post-render Callbacks in contextSafe
Animations created later, for example in pointer event handlers, sit outside the context, so they are wrapped with contextSafe taken from the hook's return value.
- 05Fall Back to gsap.context() Plus ctx.revert()
When useGSAP is not an option, the same pattern runs inside useEffect, with a cleanup that always calls ctx.revert().
- 06Keep All GSAP Code on the Client
useGSAP or useEffect is what keeps execution out of the server render; dynamic import inside useEffect is offered as an option when bundle size matters.