avoid set state on resize after component unmount #69
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey, I found an issue that happens when component unmounts on resize. The resize event triggers first which calls to the debounced callback (
action
method in the component). Because the callback is debounced, it doesn't immediately invoke theaction
method, it unmounts the component first and only then it calls the action method that uses setState on an unmounted component which leads to this error:The easiest solution I came up with is to just ignore the call because the component is unmounted anyway. There's a simple test for it too.
I do not contribute often, so I'm not sure what is the standard process (should I create an issue first?, etc..). Let me know if I need to do anything or if you have some other solution in mind so I can refactor.
(For me this issue happens when I go from desktop -> mobile break point and vise versa, there are some changes in the design and some components that use this lib get unmounted on resize)