Closed mddilley closed 5 years ago
This PR addresses cases when API requests are called in componentDidMount()
with setState()
calls chained to them. The memory leak issue pops up when a user navigates away from a view before the promise resolves, and then the app attempts to setState()
on an unmounted component.
To fix this up, a class field boolean, _isMounted
was introduced to capture the state of the component outside of its local state. _isMounted
is false
on class instantiation, set to true
in componentDidMount()
, and then set to false
again in componentWillUnmount()
. This boolean is then used as a condition for setState()
after the promise resolves. I read about this approach here and read some more about class fields here.
Closes #208