Last active
March 23, 2018 21:33
-
-
Save jacobp100/1e47d2133b9fc4810d95f7344faf16c3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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