Last active
November 29, 2017 20:57
-
-
Save gnapse/ea53bcedf94a1a32b42bfb71e50817ff to your computer and use it in GitHub Desktop.
Revisions
-
gnapse revised this gist
Nov 29, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,8 +15,8 @@ export default class MyComponent extends Component { componentDidMount() { fetch('/api/data') .then(data => this.handleSuccess(data)) .catch(error => this.handleFailure(error)); } componentWillUnmount() { -
gnapse revised this gist
Nov 29, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export default class MyComponent extends Component { }; componentDidMount() { fetch('/api/data') .then(this.handleSuccess) .catch(this.handleFailure); } -
gnapse created this gist
Nov 29, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ 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() { // ... } }