Skip to content

Instantly share code, notes, and snippets.

@albulescu
albulescu / example.js
Created February 16, 2020 02:00 — forked from dasblitz/example.js
React createFetcher explained
// This gist aims to explain how it's possible that async functions inside React
// using createFetcher(Promise).next(key) can work.
// A possible implementation of the new createFetcher function
// as shown by https://twitter.com/jamiebuilds/status/969169357094842368
// @param method, should be a function returning a Promise.
// @returns an object with a property 'read', used to read values from the resolved 'cache'.
const createFetcher = function(method) {
// First create a Map for the resolved values.
const resolved = new Map()