Created
June 4, 2018 22:35
-
-
Save goofballLogic/98387a7df0c774d181dd30a84abf085d to your computer and use it in GitHub Desktop.
This file contains 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 characters
fetchForLater().then( resp => { | |
if ( !resp.ok ) { throw new Error( "Failed to fetch for later people" ); } | |
return resp.json(); | |
} ).then( json => { | |
const savedForLater = json.map( ( [ id, person ] ) => person ); | |
this.setState( { saved: savedForLater } ); | |
} ); |
This file contains 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 characters
saveForLater( person ).then( resp => { | |
if ( !resp.ok ) { | |
throw new Error( "Failed to save person for later" ); | |
} | |
} ).then( () => { | |
const saved = this.state.saved; | |
saved.push( person ); | |
this.setState( { saved } ); | |
} ).catch( err => { | |
alert( err.message ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment