Make props in react / vue packages reactive #201
Labels
bug
Something isn't working
@viselect/preact
Preact package
@viselect/react
React package
@viselect/vue
Vue package
Is your feature request related to a problem? Please describe.
Yes, the issue is related to the event handlers (onBeforeStart, onBeforeDrag, onStart, onMove, onStop) within the SelectionArea component not having access to the latest props when the parent component's props change. As a result, the event handlers only reference the props at the initial mount of the component.
Describe the solution you'd like
An approach to solve this issue is to include the event handlers in the dependency array of the useEffect that sets up the event handlers. This ensures that the useEffect would run every time any of the event handlers changes, causing the event listeners to be re-set with the latest props.
Example:
Describe alternatives you've considered
An alternative solution is to wrap the event handler functions with useRef inside the SelectionArea component. This will allow the handlers to reference the latest props whenever they are executed without the need to re-run the useEffect. Here's an example for onStart:
Additional context
The current implementation may cause unexpected behavior for users who expect the event handlers to always reference the latest props. By implementing the suggested solution, the component will provide a more consistent and expected behavior.
Please note that this issue and the proposed solutions were created by an AI and have not been tested. It is recommended to test the suggested changes before implementing them in the actual codebase.
The text was updated successfully, but these errors were encountered: