1.0.0 • Published 4 years ago

suspense-cache v1.0.0

Weekly downloads
192
License
MIT
Repository
github
Last release
4 years ago

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:

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:

const text = cache.read('https://somewebpage.com');