@cyca/simple-create-resource
Super basic create-resource for use with React Suspense with basic global cache. Note that this doesn't respect HTTP Caching.
This project was bootstrapped with TSDX.
Credits to Ryan Florence gist source this is just that, I just added some typescript types.
Usage:
// resources.js
import { createResource } from "@cyca/simple-create-resource";
const API = createResource(url => (
fetch(url).then(res => res.json())
);
const FirebaseDoc = createResource(path => (
firebase.firestore().doc(path).get()
))
export { API, FirebaseDoc }
// somefile.js
import { API } from './resources';
API.preload('/thing');
const stuff = API.read('/thing');
API.clear('/thing');
API.clear(); // all keys