Skip to content

Instantly share code, notes, and snippets.

@klinkov
Forked from JimRottinger/parseServerResponse.js
Created June 4, 2019 17:37
Show Gist options
  • Save klinkov/42397d5add63aadf0ceb864f762ec393 to your computer and use it in GitHub Desktop.
Save klinkov/42397d5add63aadf0ceb864f762ec393 to your computer and use it in GitHub Desktop.
function mockServerCall () {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
'status': 200,
'content-type': 'application/json',
'data' : {
dataOfInterest: 42
}
})
}, 250)
})
}
mockServerCall()
.then(({data: { dataOfInterest = 100 }}) => {
console.log(dataOfInterest) // 42 (but would default to 100)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment