import { useTransition, useSpring, useChain, animated, useSpringRef } from '@react-spring/web'
function MyComponent() {
const springRef = useSpringRef()
const springs = useSpring({
ref: springRef,
from: { size: '20%' },
to: { size: '50%' },
})
const transRef = useSpringRef()
const transitions = useTransition(['hi', 'there!'], {
ref: transRef,
from: { scale: 0 },
enter: { scale: 1 },
leave: { scale: 0 },
})
// Orchestrate: spring runs first, then transition runs after spring rests
useChain([springRef, transRef])
return (
<animated.div style={{ height: springs.size, width: springs.size, background: 'blue' }}>
{transitions((style, item) => (
<animated.div style={{ width: '120px', height: '120px', background: 'green', ...style }}>
{item}
</animated.div>
))}
</animated.div>
)
}