MotionValue is used to track the state and velocity of motion values.

Type Parameters

  • V = any

Constructors

Properties

A reference to the currently-controlling Popmotion animation

clearAnimation: any
current: any

The current state of the MotionValue.

events: any

An object containing a SubscriptionManager for each active event.

hasAnimated: boolean
owner?: Owner

If a MotionValue has an owner, it was created internally within Framer Motion and therefore has no external listeners. It is therefore safe to animate via WAAPI.

prev: any

The previous state of the MotionValue.

prevFrameValue: any

The previous state of the MotionValue at the end of the previous frame.

prevUpdatedAt: any

The time prevFrameValue was updated.

stopPassiveEffect?: any
updateAndNotify: ((v, render?) => void)

Type declaration

    • (v, render?): void
    • Parameters

      • v: V
      • Optional render: boolean

      Returns void

updatedAt: any

The last time the MotionValue was updated.

version: string

This will be replaced by the build step with the latest version number. When MotionValues are provided to motion components, warn if versions are mixed.

Methods

  • Returns void

  • Destroy and clean up subscribers to this MotionValue.

    The MotionValue hooks like useMotionValue and useTransform automatically handle the lifecycle of the returned MotionValue, so this method is only necessary if you've manually created a MotionValue via the motionValue function.

    Returns void

  • Returns the latest state of MotionValue

    Returns V

    • The latest state of MotionValue
  • Returns undefined | V

  • Returns the latest velocity of MotionValue

    Returns number

    • The latest velocity of MotionValue. Returns 0 if the state is non-numerical.
  • Returns true if this value is currently animating.

    Returns boolean

  • Set the state of the MotionValue, stopping any active animations, effects, and resets velocity to 0.

    Parameters

    Returns void

  • Type Parameters

    • EventName extends keyof MotionValueEventCallbacks<V>

    Parameters

    Returns VoidFunction

  • Adds a function that will be notified when the MotionValue is updated.

    It returns a function that, when called, will cancel the subscription.

    When calling onChange inside a React component, it should be wrapped with the useEffect hook. As it returns an unsubscribe function, this should be returned from the useEffect function to ensure you don't add duplicate subscribers..

    export const MyComponent = () => {
    const x = useMotionValue(0)
    const y = useMotionValue(0)
    const opacity = useMotionValue(1)

    useEffect(() => {
    function updateOpacity() {
    const maxXY = Math.max(x.get(), y.get())
    const newOpacity = transform(maxXY, [0, 100], [1, 0])
    opacity.set(newOpacity)
    }

    const unsubscribeX = x.on("change", updateOpacity)
    const unsubscribeY = y.on("change", updateOpacity)

    return () => {
    unsubscribeX()
    unsubscribeY()
    }
    }, [])

    return <motion.div style={{ x }} />
    }

    Parameters

    Returns (() => void)

    A function that, when called, will cancel this subscription.

      • (): void
      • Returns void

    Deprecated

  • Sets the state of the MotionValue.

    Parameters

    • v: V
    • Optional render: boolean

      Whether to notify render subscribers. Defaults to true

    Returns void

    Remarks

    const x = useMotionValue(0)
    x.set(10)
  • Parameters

    • current: V

    Returns void

  • Parameters

    • Optional prevFrameValue: V

    Returns void

  • Parameters

    • prev: V
    • current: V
    • delta: number

    Returns void

  • Stop the currently active animation.

    Returns void

Generated using TypeDoc