// After class ExampleComponent extends React.Component { state = { externalData: null, }; // highlight-range{1-9} componentDidMount() { this._currentRequest = asyncLoadData( this.props.someID, externalData => { this._currentRequest = null; this.setState({externalData}); } ); } // highlight-line // highlight-range{1-5} componentWillUnmount() { if (this._currentRequest) { this._currentRequest.cancel(); } } render() { if (this.externalData === null) { // Render loading state ... } else { // Render real UI ... } } }