mouse
Track the mouse (and optionally touch) position.
| Package | @vizejs/composable/mouse |
| Own the source | vize lib pull composable:mouse |
| Runtime exports | useMouse |
| Gzip budget | 1792 B |
Usage
import { useMouse } from "@vizejs/composable/mouse";
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
useMouse |
input | experimental | deterministic-fallback | stable | caller, reactive-scope | web, desktop | window |
tryOnScopeDispose |
API
useMouse
Track the mouse (and optionally touch) position. Listens passively for mousemove, dragover, and touch events on the target; listeners follow the reactive target and are removed with the owning reactive scope. Server renders expose initialValue with a null source type.
function useMouse(options: UseMouseOptions = {}): MouseControls
Types
Point
Two-dimensional coordinate in CSS pixels.
| Member | Type | Description |
|---|---|---|
x |
number |
Horizontal coordinate. |
y |
number |
Vertical coordinate. |
UseMouseOptions
Options for useMouse.
| Member | Type | Description |
|---|---|---|
type? |
MouseCoordinateType | MouseCoordinateExtractor |
Coordinate space, or a custom extractor. |
target? |
MaybeRefOrGetter<EventTarget | null | undefined> |
Event target to listen on. |
touch? |
boolean |
Track touch input in addition to mouse input. |
resetOnTouchEnds? |
boolean |
Restore initialValue when a touch ends. |
initialValue? |
Point |
Coordinates exposed before any input and during server rendering. |
MouseControls
Reactive pointer position returned by useMouse.
| Member | Type | Description |
|---|---|---|
x |
Readonly<Ref<number>> |
Latest horizontal coordinate. |
y |
Readonly<Ref<number>> |
Latest vertical coordinate. |
sourceType |
Readonly<Ref<MouseSourceType | null>> |
Device that produced the latest coordinates; null before any input. |