Skip to content

Instantly share code, notes, and snippets.

@watanabeyu
Last active May 11, 2017 03:59
Show Gist options
  • Save watanabeyu/c57df92555ba18905c253658007e1607 to your computer and use it in GitHub Desktop.
Save watanabeyu/c57df92555ba18905c253658007e1607 to your computer and use it in GitHub Desktop.
ssrでfetchしてるときにあえてsetTimeout使って遅らせたいときの、setTimeoutの書き方
return new fetch(`/hogehoge`)
.then(response => {
return response.json().then(json => ({ status: response.status, json }))
})
.then(r => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log("settimeout finish")
resolve(0)
return dispatch({ type: "FINISH" })
}, 5000)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment