bvaughn / suspense

Utilities for working with React Suspense

Home Page:https://suspense.vercel.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

suspense

APIs to simplify data loading and caching. Primarily intended for use with React Suspense.

⚠️ Considerations

  1. Suspense is an experimental, pre-release feature; these APIs will change along with React.
  2. This package depends on react@experimental and react-dom@experimental versions.

Example

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.

If you like this project, buy me a coffee.

About

Utilities for working with React Suspense

https://suspense.vercel.app/

License:MIT License


Languages

Language:TypeScript 94.2%Language:CSS 5.2%Language:JavaScript 0.3%Language:HTML 0.2%