Created
July 8, 2020 17:59
-
-
Save bsdahl/1142d172c96d41be5aa2cca223efffad to your computer and use it in GitHub Desktop.
Staggered Fade animation on React Child Components using react-spring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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