maslianok / react-resize-detector

A Cross-Browser, Event-based, Element Resize Detection for React
http://maslianok.github.io/react-resize-detector/
MIT License
1.25k stars 91 forks source link

Presence of `ref.current` as a useEffect hook dependency. #185

Closed Gautam-Arora24 closed 2 years ago

Gautam-Arora24 commented 3 years ago

The library has ref.current as a useEffect hook dependency here which I think is of no use.

Why I came to this conclusion? I was implementing my own hook on top of ResizeObserverAPI and after adding ref.current in useEffect hook as a dependency I am getting an eslint warning which states that Mutable values like 'ref.current' aren't valid dependencies because mutating them doesn't re-render the component. (react-hooks/exhaustive-deps)

maslianok commented 2 years ago

It was discussed in this issue https://github.com/maslianok/react-resize-detector/issues/130

You'll get the bug described in the issue if you remove the ref.current from the dependency array. I put some time to fix the bug and I couldn't find a better approach to resolve it (please read my comment here https://github.com/maslianok/react-resize-detector/issues/130#issuecomment-775046806)

Thank you for the feedback. Please let me know if you have any further questions