question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE] Method to immediately set the spring value from `useSpring`, skipping the spring animation

See original GitHub issue

Is 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:open
  • Created 3 years ago
  • Reactions:14
  • Comments:6

github_iconTop GitHub Comments

5reactions
robksawyercommented, Mar 10, 2022

Any movement on this? Or is there a better approach now?

0reactions
arlyoncommented, Aug 28, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Animated! With React-Spring #2: The useSpring Hook
In the first article we took a quick look at what React-Spring is, ... Every animated value has attached to it a function...
Read more >
Making Sense of react-spring - CSS-Tricks
We'll cover springs, height animation, and then transitions. I'll have a working demo at the end of this section, so don't worry if...
Read more >
Spring Configs | React Spring
It directly controls how your springs behave and can customized on a spring by spring basis ... import { useSpring, animated } from...
Read more >
React Spring - GitHub Pages
This means you can animate 3d objects with @react-spring/three while animating DOM ... the useSpring and useSprings hooks each return an animate function....
Read more >
All You Need to Know About React Spring Jammed Into 1 Article
React Spring Examples: Using useSprings in your application · Either: overwrite values to change the animation · Or: pass a function that returns ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found