I am trying to animate breadcrumbs using react-motion from x: -20
to x: 0
.
Folder > SubFolder > Child
The issue is, the breadcrumbs animate perfectly on the first render. Subsequently when the props
or even state
changes, the animations are not updated. This seems to be a known bug.
My question is, how do I "restart" animation on state/prop changes?
const getDefaultStyles = crumbs => {
const defaultStyles = crumbs.map(() => ({x: -20}))
console.log(defaultStyles)
return defaultStyles
}
const getStyles = previousInterpolatedStyles => {
return previousInterpolatedStyles.map((_, i) => {
return i === 0 ? {x: spring(0)} : {x: spring(previousInterpolatedStyles[i-1].x)}
})
}
const Breadcrumb = ({ crumbs }) => (
<div className='breadcrumb-container'>
<StaggeredMotion
defaultStyles={getDefaultStyles(crumbs)}
styles={getStyles}>
{
interpolatedStyles =>
<div className='breadcrumb-list'>
{
interpolatedStyles.map(({x}, i) =>
<div className='breadcrumb' key={i} style={{
WebkitTransform: `translate3d(${x}px, 0, 0)`,
transform: `translate3d(${x}px, 0, 0)`
}}>
<a href='#'>Title</a>
</div>
)
}
</div>
}
</StaggeredMotion>
</div>
)
key
prop toDate.now()
solved my issue since I always want to re-animate when a new flash msg appears. – Uel