Skip to content

Instantly share code, notes, and snippets.

@jacobp100
Last active March 23, 2018 21:33
Show Gist options
  • Save jacobp100/1e47d2133b9fc4810d95f7344faf16c3 to your computer and use it in GitHub Desktop.
Save jacobp100/1e47d2133b9fc4810d95f7344faf16c3 to your computer and use it in GitHub Desktop.
const createDataFetcher = (url) => {
let result = null
let promise = null
return () => {
if (result != null) {
return result;
}
if (promise === null) {
promise = fetch(url).then(value => {
result = value
})
}
throw promise
}
}
const fetchUser = createDataFetcher('http://website.com/users/me')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment