import React, { Component } from ‘react’; const noop = () => {}; export default class MyComponent extends Component { state = { data: null, error: null }; handleSuccess = data => { this.setState({ data }); }; handleFailure = error => { this.setState({ error }); }; componentDidMount() { fetch('/api/data') .then(data => this.handleSuccess(data)) .catch(error => this.handleFailure(error)); } componentWillUnmount() { this.handleSuccess = noop; this.handleFailure = noop; } render() { // ... } }