useTrail
Overview
import { useTrail, animated } from 'react-spring'
Creates multiple springs with a single config, each spring will follow the previous one. Use it for staggered animations.
Either: overwrite values to change the animation
If you re-render the component with changed props, the animation will update.
const trail = useTrail(amount, { opacity: 1 })
Or: pass a function that returns values, and update using "set"
You will get an API object back. It will not cause the component to render like an overwrite would (the animation still executes of course). Handling updates like this is useful for fast-occurring updates, and you should generally prefer it as it's more powerful. Further documentation can be found in Imperatives & Refs
const [trail, api] = useTrail(amount, () => ({ opacity: 1 }))
// Update trail
api.start({ opacity: 0 })
// Stop trail
api.stop()
Finally: distribute animated props among the view
The return value is an array containing animated props.
return trail.map((styles) => <animated.div style={styles} />)
Properties
All properties of the shared-api apply.