I’m trying to create an event handler for the mouseMove event, but I can’t figure out what the type of the event handler is supposed to be.
When I hover over onMouseMove
, it says the type is MouseEventHandler<HTMLButtonElement>
. But when I try using that type, I get the following error:
Type '(e: MouseEventHandler<HTMLButtonElement>) => void' is not assignable to type 'MouseEventHandler<HTMLButtonElement>'.
Types of parameters 'e' and 'event' are incompatible.
Type 'MouseEvent<HTMLButtonElement, MouseEvent>' is not assignable to type 'MouseEventHandler<HTMLButtonElement>'.
Type 'MouseEvent<HTMLButtonElement, MouseEvent>' provides no match for the signature '(event: MouseEvent<HTMLButtonElement, MouseEvent>): void'.
So I tried using e: MouseEvent<HTMLButtonElement, MouseEvent>
, but then I get the error: Type 'MouseEvent' is not generic.
Can someone help me out here? What’s the type of e
supposed to be?
function Button() {
function handleMouseMove(e: MouseEventHandler<HTMLButtonElement>) {
// ...
}
return (
<button onMouseMove={handleMouseMove}>
// ...
</button>
)
}