useMotionValueEvent
useMotionValueEvent
manages a motion value event handler throughout the lifecycle of a React component.
When the component is unmounted, event handlers will be safely cleaned up.
Usage
Import from Motion:
To add an event listener to a motion value, provide the value, event name and callback:
Available events are:
change
animationStart
animationComplete
animationCancel
"change"
events are provided the latest value of the motion value.
Advanced
useMotionValueEvent
is a helper function for a motion value's on
method. With on
, you can start listening to events whenever you like, for instance within an event handler. But remember to also unsubscribe when the component unmounts.