Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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/).