Hi.
I've found that I can't use getBoundingClientRect with MouseEvent in typescript.
onClick: (event: MouseEvent): void => {
const { left, top } = event.target.getBoundingClientRect();
const { left, top } = event.nativeEvent.target.getBoundingClientRect();
},
Typescript message I see in VS code is:
Property 'getBoundingClientRect' does not exist on type 'EventTarget'.ts(2339)
This is what worked for me, but I guess for MouseEvent
it should work out of the box
const node = event.target as HTMLElement;
this looks like an issue for the typescript bindings, the react team doesn't own those.
Most helpful comment
This is what worked for me, but I guess for
MouseEvent
it should work out of the boxconst node = event.target as HTMLElement;