Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bvaughn/suspense
Utilities for working with React Suspense
https://github.com/bvaughn/suspense
async caching data fetching loading react suspense
Last synced: 25 days ago
JSON representation
Utilities for working with React Suspense
- Host: GitHub
- URL: https://github.com/bvaughn/suspense
- Owner: bvaughn
- License: mit
- Created: 2023-02-21T02:37:26.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-06T16:48:15.000Z (8 months ago)
- Last Synced: 2024-10-20T04:39:40.773Z (27 days ago)
- Topics: async, caching, data, fetching, loading, react, suspense
- Language: TypeScript
- Homepage: https://suspense.vercel.app/
- Size: 859 KB
- Stars: 416
- Watchers: 7
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# suspense
APIs to simplify data loading and caching. Primarily intended for use with [React Suspense](https://beta.reactjs.org/blog/2022/03/29/react-v18#suspense-in-data-frameworks).
#### ⚠️ Considerations
1. Suspense is an experimental, pre-release feature; **these APIs will change** along with React.
1. This package depends on `react@experimental` and `react-dom@experimental` versions.#### Example
```js
import { createCache } from "suspense";const userProfileCache = createCache({
load: async ([userId]) => {
const response = await fetch(`/api/user?id=${userId}`);
return await response.json();
},
});function UserProfile({ userId }) {
const userProfile = userProfileCache.read(userId);// ...
}
```More examples at [suspense.vercel.app](https://suspense.vercel.app/).
#### If you like this project, [buy me a coffee](http://givebrian.coffee/).