You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I am creating a smooth scroll with framer motion doing the following:
...
const{ scrollY }=useViewportScroll();consttransform=useTransform(scrollY,(value)=>factor*value);constframerScrollY=useSpring(transform,framerSmoothScrollPhysics);setFramerScrollY(framerScrollY)// zustand method to update the store...
I want to store the smoothScrollY in a zustand store so I can access this value accross multiple components.
I am using the subscribe method of zustand to create a hook and get store value update without triggering a rerender.
In a raf loop, I can confirm that the value of the motion in the store is updated, but when I try to use it with framer useTransform, it seems the value is not used:
constframerScrollY=useFramerScrollY();// my hook that gets the value from the zustand store that doesn't trigger a rerender// PROGRESS REMAINS 0constprogress=useTransform(framerScrollY,bounds,[0,1],{ clamp });// but framerScrollY.current.current is correctly updateduseRaf(()=>{console.log(progress.current,framerScrollY.current.current);});
However, if I apply the same logic as I did to create the smooth effect, the value gets updated:
const{ scrollY }=useViewportScroll();consttransform=useTransform(scrollY,(value)=>factor*value);constframerScrollY=useSpring(transform,framerSmoothScrollPhysics);// PROGRESS IS UPDATEDconstprogress=useTransform(framerScrollY,bounds,[0,1],{ clamp });
Is there a way to store the motion value in a react/zustand context/store and get framer to update its value or the way to do it is to factorize the part of the code that create the smooth effect and use it as a base for all other components depending on it?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I am creating a smooth scroll with framer motion doing the following:
I want to store the smoothScrollY in a zustand store so I can access this value accross multiple components.
I am using the
subscribe
method of zustand to create a hook and get store value update without triggering a rerender.In a raf loop, I can confirm that the value of the motion in the store is updated, but when I try to use it with framer useTransform, it seems the value is not used:
However, if I apply the same logic as I did to create the smooth effect, the value gets updated:
Is there a way to store the motion value in a react/zustand context/store and get framer to update its value or the way to do it is to factorize the part of the code that create the smooth effect and use it as a base for all other components depending on it?
Thanks in advance for the help.
Beta Was this translation helpful? Give feedback.
All reactions