Skip to content
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

Get current value from useTransform not working #7

Open
myhrmans opened this issue Jul 20, 2021 · 1 comment
Open

Get current value from useTransform not working #7

myhrmans opened this issue Jul 20, 2021 · 1 comment

Comments

@myhrmans
Copy link

myhrmans commented Jul 20, 2021

Hi. Trying to get the value returned from useTransorm but the current value that is returned stays the same.
But the div that is reading the color value is however updating.. Am I doing anything wrong here?

    const y = useMotionValue(0);
    const yInput = [-20, -0.1, 0, 0.1, 20];
    let background = useTransform(y, yInput, [
        "#FF0000",
        "#00FF00",
        "#202224",
        "#00FF00",
        "#0000FF",
    ]);

    $: console.log("Background:", background) //this line outputs each change but not the change in the value. 


  **** unimportant lines ****

<Motion
    drag={dragEnabled}
    dragConstraints={{ top: 0, left: 0, right: 0, bottom: 0 }}
    dragElastic={{ top: 0.1, left: 0.1, right: 0.1, bottom: 0.1 }}
    onDragEnd={dragEnd}
    onPanEnd={panEnd}
    onDrag={onDrag}
    dragDirectionLock={true}
    style={{ y, background }}
    let:motion
>

*div*

</Motion>

@micha-lmxt
Copy link
Owner

Hi,

useTransform returns a store. You can use auto subscription ($ before background):

$: console.log("Background:", $background)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants