I want to store the previousValue of scrollYProgress of framer motion. I want to render something depending on the difference between previous and latest value. How to get and store it?
useMotionValueEvent(scrollYProgress, "change", (latest) => {
console.log(scrollYProgress.get());
});
2
Answers
I did it with my own. It was the solution:
To achieve this in Framer Motion, you can use React’s useState hook to store the previous and latest values of scrollYProgress. Here’s an example of how you can modify your code:
In this example, previousScrollYProgress is a state variable that holds the previous value of scrollYProgress. Whenever the scrollYProgress changes, it calculates the difference between the previous and latest values and then updates the state with the latest value for the next iteration. This way, you have access to both the previous and latest values in the event handler.