Skip to content

bvaughn/suspense

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0f51aa6 · Mar 6, 2024
Apr 25, 2023
Mar 5, 2023
Mar 6, 2024
Feb 22, 2023
May 29, 2023
May 29, 2023
Feb 22, 2023
Feb 22, 2023
Feb 22, 2023
Mar 4, 2023
Feb 21, 2023
Mar 18, 2023
May 29, 2023
Dec 15, 2023
Jul 4, 2023
Mar 4, 2023
Jun 8, 2023
Feb 22, 2023

Repository files navigation

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.