medium10 pts · first answer countsreact-hooksmemory-leaks
Resize handler that runs many times
After opening and closing this panel a few times, every window resize runs the handler several times, even for panels that are already closed. What is the fix?
useEffect(() => {
window.addEventListener('resize', () => setWidth(window.innerWidth))
}, [])Discussion 0
Join free to post in the discussion.
Related questions
- Stale value in useEffectFrontend Developer
- Ref value not shown on screenFrontend Developer
- Syncing derived values with an effectFrontend Developer
- Race condition in data fetchingFrontend Developer
- Effect that fetches foreverFrontend Developer
- Tooltip flashes in the wrong placeFrontend Developer
- Memory grows in a single-page appFrontend Developer
- Listener without effect cleanupMobile App Developer