Skip to content

Instantly share code, notes, and snippets.

@bsdahl
Created July 8, 2020 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsdahl/1142d172c96d41be5aa2cca223efffad to your computer and use it in GitHub Desktop.
Save bsdahl/1142d172c96d41be5aa2cca223efffad to your computer and use it in GitHub Desktop.
Staggered Fade animation on React Child Components using react-spring
import React from 'react';
import { animated, useTrail } from 'react-spring';
export const StaggeredFade = ({ children, ...props }) => {
const trail = useTrail(React.Children.count(children), {
from: { opacity: 0 },
to: { opacity: 1 },
config: { mass: 1, tension: 280, friction: 60, clamp: true },
});
return React.Children.map(children, (child, index) => (
<animated.div style={trail[index]}>{React.cloneElement(child)}</animated.div>
));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment