Skip to content

Instantly share code, notes, and snippets.

@timdorr
Created September 13, 2017 19:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timdorr/fa5f76c8e4d44cfd52985ab7fb894c39 to your computer and use it in GitHub Desktop.
Save timdorr/fa5f76c8e4d44cfd52985ab7fb894c39 to your computer and use it in GitHub Desktop.
As async memoized data fetching singleton
const tokenPromise = new Promise(async resolve => {
const { token } = await (await fetch('/api/tokens', {
method: 'POST',
credentials: 'include'
})).json()
resolve(token)
})
export default tokenPromise
@timdorr
Copy link
Author

timdorr commented Sep 13, 2017

import tokenPromise from './token'
const token = await tokenPromise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment