react-spring: useTrail wont re animate if count of items stays the same.

πŸ› Bug Report

(A clear and concise description of what the bug is.)

To Reproduce

Try to animate your list while keeping the length of the list same Steps to reproduce the behavior:

Expected behavior

Should animate even if count stays the same.

Link to repro (highly encouraged)

https://codesandbox.io/s/sweet-hooks-xgpse?fontsize=14

Environment

  • react-spring v8.x.x
  • react v16.8.x (or react-native v0.58.x)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 23 (7 by maintainers)

Most upvoted comments

Try set reset: true https://www.react-spring.io/docs/hooks/api, works for me.

I do not believe this is a problem with react-spring, but an issue with react. When setting state, if i recall correctly, state checks to see if the state is the same or different. If the state is the same, than react does not change it, and therefore since state does not change, react does not re-render, therefore react spring does not animate because react has not changed anything.

The solution Alec is referring to with useTransition would be to make the button on click, mount and unmount the components. Instead of using useTrail, set up the same thing with useTransition, then set the trail prop to true.

There is a change in state and that is not a react issue. The implementation of react spring probably uses useEffect to detect changes and its being based on length/ count. There should be deeper detection like item.key to see if items have changed.

as a trail prop

Could you display on sandbox how to do it to achieve what we are discussing?

after playing around I don’t see how useTransition can help me.