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

Deconstructing useMotions() returns undefined #109

Open
madsh93 opened this issue Apr 13, 2023 · 4 comments
Open

Deconstructing useMotions() returns undefined #109

madsh93 opened this issue Apr 13, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@madsh93
Copy link

madsh93 commented Apr 13, 2023

Following the examples from the docs:
https://motion.vueuse.org/directive-usage.html#access-a-v-motion-instance

<template>
  <div
    v-motion="'custom'"
    :initial="{ opacity: 0, y: 100 }"
    :enter="{ opacity: 1, y: 0 }"
    :variants="{ custom: { scale: 2 } }"
  />

<button type="button" @click="customEvent">
  Click me
</button>

</template>

<script setup>
import { useMotions } from '@vueuse/motion'

// Get custom controls
const { custom } = useMotions()

const customEvent = () => {
   console.warn(custom)   // <-- Returns undefined
  custom.variant.value = 'custom' // <-- Does not work
}
</script>

Note the custom from useMotions() is undefined

Tested on v. 2.0.0-beta.27

@kranachan
Copy link

Same problem, try not to deconstruct it:
const motions = useMotions()

@Naimzz
Copy link

Naimzz commented Jun 2, 2023

Tested on v. 2.0.0-beta.27 and v. 2.0.0, accessing useMotions() with or without deconstruct is always empty ( equals to empty object )

@idflood
Copy link

idflood commented Jun 12, 2023

I recently encoutered the same issue. After adding a few console log (or just randomly?) the useMotion started working again but it was not stable, and after reloading and/or restarting nuxt it broke again.

I got it working again after downgrading nuxt to 3.4.3 and deleting the .nuxt folder.

@BobbieGoede
Copy link
Collaborator

It looks like this is due to the properties on the object returned by useMotions being set after script is run. As mentioned already, a possible workaround would be not to deconstruct the object.

I'll mark this a bug since deconstruction is shown as an example in the documentation, will investigate it later!

@BobbieGoede BobbieGoede added the bug Something isn't working label Feb 23, 2024
@BobbieGoede BobbieGoede changed the title Accessing a v-motion instance seems broken Deconstructing useMotions() returns undefined Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants