Skip to content

Instantly share code, notes, and snippets.

@timdorr
Created September 13, 2017 19:36
Show Gist options
  • Select an option

  • Save timdorr/fa5f76c8e4d44cfd52985ab7fb894c39 to your computer and use it in GitHub Desktop.

Select an option

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

timdorr commented Sep 13, 2017

Copy link
Copy Markdown
Author
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