https://github.com/samypesse/suspense-cache
Cache utility to create resources for React suspense
https://github.com/samypesse/suspense-cache
react suspense
Last synced: 6 months ago
JSON representation
Cache utility to create resources for React suspense
- Host: GitHub
- URL: https://github.com/samypesse/suspense-cache
- Owner: SamyPesse
- Created: 2019-12-30T11:24:43.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-30T12:13:54.000Z (almost 6 years ago)
- Last Synced: 2025-03-18T14:42:37.241Z (7 months ago)
- Topics: react, suspense
- Language: TypeScript
- Size: 70.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# suspense-cache
Cache utility to create resources for React suspense. This module is an alternative to `react-cache` which has not been updated.
This module should be used to create a cache that will throw a promise when pending.
## Usage
For example with a cache to fetch an URL:
```ts
import { createCache } from 'suspense-cache';const cache = createCache(
async url => {
const res = await fetch(url);
return await res.text();
}
);
```Then during rendering, the cache can be used:
```ts
const text = cache.read('https://somewebpage.com');
```