motion icon indicating copy to clipboard operation
motion copied to clipboard

Wrong writing leads to loss of 'MayRef' responsiveness

Open xiankq opened this issue 1 year ago โ€ข 0 comments

unref should be placed in computed like:


export function useMotionVariants<T extends MotionVariants>(variants: MaybeRef<T> = {} as MaybeRef<T>) {
  // Unref variants
   //โ†“โ†“โ†“โ†“โ†“โ†“โ†“
  // const _variants = unref(variants) as T

  // Current variant string
  const variant = ref() as Ref<keyof T>

  // Current variant state
  const state = computed<Variant | undefined>(() => {
    if (!variant.value) return
    //โ†“โ†“โ†“โ†“โ†“โ†“โ†“
    const _variants = unref(variants) as T
    return _variants[variant.value]
  })

  return {
    state,
    variant,
  }
}

xiankq avatar Jun 01 '23 08:06 xiankq