ethanselzer / react-cursor-position

A React component that decorates its children with mouse and touch coordinates relative to itself.
https://ethanselzer.github.io/react-cursor-position
MIT License
143 stars 35 forks source link

init() function not called when the cursor is inside the component on mount. #16

Closed aminy closed 6 years ago

aminy commented 6 years ago

We've experienced this issue, when clicking on a button renders a ReactCursorPosition component, but the cursor is already inside the new component.

In this case, the init() function will not be called until the mouse exits and entered the component again.

An easy fix for this is to call init() function in onComponentDidMount.

I will include a PR to fix this issue.

ethanselzer commented 6 years ago

Hi @aminy - Thanks for opening this issue. What you report sounds good, but I'm having trouble reproducing the issue. I created an example of rendering an instance of react-cursor-position in response to a button click event, but In my case react-cursor-position becomes active without needing to re-enter the mouse cursor. Please see my example and let me know what I'm missing. Thanks!

ethanselzer commented 6 years ago

@aminy - I'm closing this for now due to lack of activity. Please let me know if you have any further thoughts. Thanks!