https://github.com/cvpcasada/simple-create-resource
Super basic create resource api for React Suspense
https://github.com/cvpcasada/simple-create-resource
react react-suspense
Last synced: about 1 year ago
JSON representation
Super basic create resource api for React Suspense
- Host: GitHub
- URL: https://github.com/cvpcasada/simple-create-resource
- Owner: cvpcasada
- License: mit
- Created: 2020-02-04T11:49:41.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T06:26:12.000Z (over 3 years ago)
- Last Synced: 2025-01-08T23:25:24.366Z (over 1 year ago)
- Topics: react, react-suspense
- Language: TypeScript
- Size: 1.35 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @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](https://gist.github.com/ryanflorence/e10cc9dbc0e259759ec942ba82e5b57c#gistcomment-3114667).
This project was bootstrapped with [TSDX](https://github.com/jaredpalmer/tsdx).
Credits to [Ryan Florence](https://github.com/ryanflorence) [gist source](https://gist.github.com/ryanflorence/e10cc9dbc0e259759ec942ba82e5b57c) this is just that, I just added some typescript types.
```js
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 }
```
```js
// somefile.js
import { API } from './resources';
API.preload('/thing');
const stuff = API.read('/thing');
API.clear('/thing');
API.clear(); // all keys
```