-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[useSpring] onStart callback triggered on each frame #335
Comments
the problem is useSpring updates the internal animation controller on every rerender(i.e every time you call setState). there should be some sore of diffing of props, i.e if the props passed down are the same, then skip update. |
That's interesting. onStart in hooks, i have to think about it. It's true that if you update, it theoretically "starts" - whatever this means, this is where the lines between declarative and imperative get blurry. |
@ruggedy it stopped running So I tried using the In this case, the component is not re-rendered on drag, so I wouldn't expect I'm sure there is a logic explanation for all this, and maybe we're reaching the limits of hooks there I don't know 😅 |
@dbismut yh it is actually working correctly, because now you are updating the internal animation controller everytime just a suggestion, as I havent used react-with-gesture yet, but maybe instead of listening to mousedown event, you can listen to the mouseup event, and animate from that position back to zero. this is what I assume the code might look like.
just a wild guess. edit: just checked and realised that you were using react spring to set the translate based on the mousemove xDelta. so the above will not work. but I will keep looking into this and let you know once I have something. |
This is fixed in v9, which you can now try: Let us know how it goes: #642 |
Yes this does work, thanks @aleclarson! |
Hey! Thanks for this fantastic library.
I'm trying the
useSpring
hook which I understand is experimental, and maybe this is by design or maybe this is me not usinguseCallback
or misusing hooks, but I findonStart
being triggered on each frame.Here is the isolated codesandbox showing the issue: https://codesandbox.io/s/oj9y6j6z9q
As you can see, dragging the box triggers a
console.log
at each frame.If you uncomment the commented
onStart
function which increments a state counter, theonStart
function is run continuously...The text was updated successfully, but these errors were encountered: