I am using the useTransition hook from React Spring to animate an array of strings stored in an usestate.
The animation removes and vertically scrolls each digit, but when the array contains duplicate digits it removes and adds elements twice.
const [lista, setLis] = useState(['5', '0']);
const hour = useTransition(lista, {
from: { opacity: 0, y: -50 },
enter: { opacity: 1, y: 0 },
leave: { opacity: 0, y: 50 },
exitBeforeEnter: true,
config: { duration: 400 },
});
{hour((style, cont) => (
<animated.div style={style}>
<h2 className="mb-0 text-warning" style={style}>
{cont}
</h2>
</animated.div>
))}
I am aware this is due to how useTransition handles updates, but is there any way to bypass this without needing to have a single useTransition for each digit?
Complete example Here
Try this, I'm not 100% sure if you were talking about this solution, but it seems logical to me.