I'm rethinking useCanvasEvents a bit. The hook is now called useCanvasEvent (singular) and allows registering only one event listener at a time. This brings the API closer to that of useEventListener from react-hookz and avoids registering event listeners that are not actually used.
Additional benefits of the new implementation:
It allows more events to be registered, not just pointerdown, pointerup, pointermove and wheel — so basically any event that has offsetX and offsetY (i.e. any event that extends MouseEvent, including WheelEvent, PointerEvent, DragEvent).
It uses useSyncedRef so consumers don't have to wrap their listeners in useCallback — this simplifies a bunch of code.
It allows overriding the options passed to addEventListener, notably passive, which might be useful at some point notably for wheel events (currently, the only place where we do need to configure passive is in useWheelCapture but it doesn't rely on useCanvasEvent).
I'm rethinking
useCanvasEvents
a bit. The hook is now calleduseCanvasEvent
(singular) and allows registering only one event listener at a time. This brings the API closer to that ofuseEventListener
from react-hookz and avoids registering event listeners that are not actually used.Additional benefits of the new implementation:
pointerdown
,pointerup
,pointermove
andwheel
— so basically any event that hasoffsetX
andoffsetY
(i.e. any event that extendsMouseEvent
, includingWheelEvent
,PointerEvent
,DragEvent
).useSyncedRef
so consumers don't have to wrap their listeners inuseCallback
— this simplifies a bunch of code.addEventListener
, notablypassive
, which might be useful at some point notably forwheel
events (currently, the only place where we do need to configurepassive
is inuseWheelCapture
but it doesn't rely onuseCanvasEvent
).