Skip to content

Instantly share code, notes, and snippets.

@goofballLogic
Created June 4, 2018 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goofballLogic/98387a7df0c774d181dd30a84abf085d to your computer and use it in GitHub Desktop.
Save goofballLogic/98387a7df0c774d181dd30a84abf085d to your computer and use it in GitHub Desktop.
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 } );
} );
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