[FEATURE] Method to immediately set the spring value from `useSpring`, skipping the spring animation
See original GitHub issueIs your feature request related to a problem? Please describe.
Currently, there is no documented way to immediately set the current value of a MotionValue
returned by useSpring
. Calling .set(value, false)
continues to play the spring animation even if render subscribers are not notified. This results in strange animation when the spring value is updated frequently.
See: https://codesandbox.io/s/framer-motion-hover-issue-59cd0?file=/src/App.tsx
In this example, setting the spring value in the onMouseEnter
handler and then setting it again in response to subsequent onMouseMove
events causes the animation to look janky, as these events fire in quick succession.
Describe the solution you’d like
There should be some public API on the MotionValue
class that allows you to immediately set the current value of the spring while skipping the spring animation. Exposing .current
and .prev
as mutable public properties, skipping the animation on .set(value, false)
, or introducing a new method such as .immediate(value)
are possible solutions.
Describe alternatives you’ve considered
As far as I know, the only way to do this is to mutate the private property .current
of the MotionValue
. This works, but Typescript does not like it.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:6
Top GitHub Comments
Any movement on this? Or is there a better approach now?
As a concrete usecase, I have an item that I want to be able to move around in response to outside state, while also being able to drag it to a new value. Currently, it all works, except if I drag somwhere else, as soon as I let go, due to how it is implemented, the object snaps back to its spring location before ‘springing’ over.