Skip to content

Instantly share code, notes, and snippets.

@loopmode
loopmode / DefaultComponent.js
Last active July 9, 2020 08:34
Safeguarding async chains in React
// we have an async "initialize" method that performs several calls consecutively.
// after each step in the async chain, we might have been unmounted already
// and performing any further calls becomes obsolete
class DefaultComponent extends React.Component {
// ...
componentDidMount() {
this._isMounted = true;
this.initialize();
}
componentWillUnmount() {