Created
September 13, 2017 19:36
-
-
Save timdorr/fa5f76c8e4d44cfd52985ab7fb894c39 to your computer and use it in GitHub Desktop.
As async memoized data fetching singleton
This file contains 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 tokenPromise = new Promise(async resolve => { | |
const { token } = await (await fetch('/api/tokens', { | |
method: 'POST', | |
credentials: 'include' | |
})).json() | |
resolve(token) | |
}) | |
export default tokenPromise |
Author
timdorr
commented
Sep 13, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment