Fade-in animation with requestAnimationFrame
AnimationanimationperformanceuseEffectrequestAnimationFrameCSS-in-JS
A performant, CSS-in-JS fade-in animation using useState, useEffect, and requestAnimationFrame for smooth entrance transitions.
This component fades in content smoothly when it enters the viewport, using requestAnimationFrame for jank-free rendering and IntersectionObserver for efficient visibility detection. It avoids layout thrashing by setting will-change and disabling conflicting CSS transitions. To use, wrap any JSX with <FadeIn>...</FadeIn>. Note: The animation is triggered only once on mount/intersection — no re-triggering on re-renders. For multiple elements, use separate instances or extend with a key-based approach.