Adding Motion to React Portfolios with GSAP
Most developers spend hours agonizing over layout and color schemes, only to launch a static portfolio that feels like a tombstone rather than a living showcase. I recently decided to breathe some life into my tonybnya/portfolio project by integrating GSAP (GreenSock Animation Platform) to handle element transitions.
The Problem with Static Pages
Standard CSS transitions are great for simple hover states, but they quickly hit a ceiling when you need sequenced animations—like fading in multiple elements in a specific order after a page load or a successful form submission.
My "Thanks" page was suffering from this. It was a cold, abrupt dead-end. I wanted a way to guide the user's focus naturally after they submitted their contact information.
Why GSAP?
Instead of wrestling with complex CSS keyframe syntax that is hard to maintain, I opted for GSAP. It acts like a choreographer for the DOM. Here is how I set up a simple entrance animation using a React hook:
import { useEffect, useRef } from 'react';
import gsap from 'gsap';
const ThanksComponent = () => {
const containerRef = useRef(null);
useEffect(() => {
gsap.fromTo(containerRef.current,
{ opacity: 0, y: 20 },
{ opacity: 1, y: 0, duration: 1, ease: "power2.out" }
);
}, []);
return <div ref={containerRef}>Thank you for your message!</div>;
};
Implementation Strategy
- Ref Management: Using
useRefto target the specific DOM element ensures GSAP doesn't interfere with React's reconciliation process. - Clean Up: Always ensure animations are killed or cleared if the component unmounts to prevent memory leaks in single-page applications.
- Sequential Flow: I used GSAP timelines to chain entrance animations, making the content feel orchestrated rather than chaotic.
The Takeaway
Animations should be like a good soundtrack in a movie: they shouldn't distract the user, but they should subtly enhance the mood. If you're building a personal site, start small with simple entrance transitions. A little bit of motion goes a long way in showing that you care about the user's experience.
Generated with Gitvlg.com