Removing calls to setState after unmount (#139) #140
Closed
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.
Issue #139 was the same issue I was having when resizing a window.
I was receiving an error about a possible memory leak since setState
was called on an unmounted component. It seems like the
getMatches
call was taking just long enough that the component could be unmounted
while it was executing. By using a
_mounted
flag, we can determineif it is safe to call
setState
and bypass it if the component isunmounted. I looked at using an abort signal, but I don't think the
matchMedia
API is robust enough for that currently.