The structure of your configuration object depends on whether you are using gesture-specific hooks, the general useGesture hook, or the Vanilla JavaScript classes (DragGesture or Gesture).
- Gesture-specific hooks: Pass shared options and gesture-specific options in a single object.
useGesture hook: Pass an object containing event handlers (e.g., onDrag, onPinch) as the first argument, and a second object containing shared options and gesture-specific configuration objects (e.g., drag: { ... }).- Vanilla Classes:
DragGesture: Pass the element, handler, and a single config object containing shared and drag-specific options.Gesture: Pass the element, an object of handlers, and a second object containing shared and gesture-specific configuration objects.
// when you use a gesture-specific hook
useDrag((state) => doSomethingWith(state), { ...sharedOptions, ...dragOptions })
// when you use the useGesture hook
useGesture(
{
onDrag: (state) => doSomethingWith(state),
onPinch: (state) => doSomethingWith(state)
// ...
},
{
// global options such as `target`
...sharedOptions,
// gesture specific options
drag: dragOptions,
wheel: wheelOptions,
pinch: pinchOptions,
scroll: scrollOptions,
hover: hoverOptions
}
)
// when you use a gesture-specific class
new DragGesture(
element,
state => doSomethingWith(state),
{ ...sharedOptions, ...dragOptions }
)
// when you use the Gesture class
new Gesture(element, {
onDrag: state => doSomethingWith(state),
onPinch: state => doSomethingWith(state),
// ...
{
// global options such as `target`
...sharedOptions,
// gesture specific options
drag: dragOptions,
wheel: wheelOptions,
pinch: pinchOptions,
scroll: scrollOptions,
wheel: wheelOptions,
hover: hoverOptions,
}
})