element-resize-detector not removed correctly on componentWillUnmount
See original GitHub issueI’m using this library in a react-router
application and I have issues when using several detectors in different routes. On the first route, resize events are sent but when I go on a new route, then the library don’t send the dimensions anymore.
After a bit of investigations, I found that the element-resize-detector
needs to be uninstall on componentWillUnmount
since it is instantiated on each componentDidMount
. (See https://github.com/wnr/element-resize-detector#uninstallelement).
This block should be replaced by:
componentWillUnmount() {
this.elementResizeDetector.uninstall(this.parentNode)
}
Then, everything works properly in React Router…
Do you want me to submit a Pull Request for this?
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
Rerender view on browser resize with React - Stack Overflow
I have some blocks that I want to layout individually on the page, however I also want them to update when the browser...
Read more >Cross-Browser, Event-based, Element Resize Detection
The other method is removeResizeListener , and it ensures that your listeners are properly detached when you want them removed.
Read more >react-resize-detector - npm
TypeScript-lovers notice: starting from v6. 0.0 you may safely remove @types/react-resize-detector from you deps list.
Read more >How to work with React the right way to avoid some common ...
Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application...
Read more >Container Queries And Element Resize Detection As We ...
The simplicity of this idea is deceiving. While it seems simple for a case where you have a container with a set width,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would write a test that should check if the
this.elementResizeDetector
is properly uninitialized. Check out the existing tests and try it out. If you have question, please don’t hesitate to reach out to me and I’ll try to help!Indeed, you are right, this is exactly how I modified the test to understand the issue 😃