APIs to simplify data loading and caching. Primarily intended for use with React Suspense.
- Suspense is an experimental, pre-release feature; these APIs will change along with React.
- This package depends on
react@experimental
andreact-dom@experimental
versions.
If you like this project, 🎉 become a sponsor or ☕ buy me a coffee
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.