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(this.handleSuccess) .catch(this.handleFailure); } componentWillUnmount() { this.handleSuccess = noop; this.handleFailure = noop; } render() { // ... } }