useMousePressed
A React Hook that tracks mouse pressed state.
Demo
SourceMouse Pressed (target): false
Source Type (target): null
Target
Usage
See API for more details.
Source
Click links below to view source on GitHub.
API
const { pressed, sourceType } = useMousePressed(elementTarget, options)
ElementTarget
ElementTarget
is a union type that represents various kinds of elements that can be targeted.
See ElementTarget or ElementTarget Types for more details.
Options
export type MousePressedOptions = {
/**
* Whether to listen to touch events
*
* @defaultValue true
*/
touch?: boolean
/**
* Whether to listen to drag events
*
* @defaultValue true
*/
drag?: boolean
/**
* Whether to use event capturing
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#capture MDN - addEventListener#capture}
*
* @defaultValue false
*/
capture?: boolean
/**
* The initial value of the mouse press
*
* @defaultValue false
*/
initialValue?: boolean
/**
* The target element
*
* @defaultValue () => window
*/
target?: ElementTarget
}
Returns
export type UseMousePressedReturns = {
/**
* Whether the mouse is pressed
*/
pressed: boolean
/**
* The source type of the mouse press
*/
sourceType: UseMouseSourceType
}