pmndrs / react-spring

✌️ A spring physics based React animation library
http://www.react-spring.dev/
MIT License
27.73k stars 1.18k forks source link

fix: useTransition hook works correctly with a function argument. (#2287) #2289

Open Roman178 opened 3 weeks ago

Roman178 commented 3 weeks ago

Why

https://github.com/pmndrs/react-spring/issues/2287. The useTransition hook doesn't work correctly if we pass a function as an argument.

What

If we pass a function to the hook, a ref variable will be created, an instance of SpringRef. Then, as stated in the comment, if the ref exists, the update is postponed until the ref's start method is called. By calling the ctrl update method, we simply put another item in the queue. Perhaps I didn’t fully understand it, but I didn’t see calling the start method on an existing ref that flushes the queue.

Calling the ref's start method in useIsomorphicLayoutEffect solves the problem.

image

Checklist

changeset-bot[bot] commented 3 weeks ago

⚠️ No Changeset found

Latest commit: 3b762e4f094ee0dbb117352fded711de5b8241c4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

vercel[bot] commented 3 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
react-spring ✅ Ready (Inspect) Visit Preview Jun 12, 2024 1:53pm