The async function that will be called when suspending.
If need to respond to different arguments, you can use bindKeyedSuspense instead.
Optional
storage?: Storage(Advanced) You can provide the backing cache object
By default it uses an internal implementation based on a simple variable, but you can provide your own implementation
Access to the backing cache.
Useful for doing cache.set(null)
, and force a re-fetch.
Suspend your tree while the async function resolves, and return its promise's value
import { bindSuspense } from "@cprecioso/react-suspense";
const appConfig = bindSuspense(() =>
fetch("/api/config").then((res) => res.json())
);
export const Greeting = () => {
const { accentColor } = appConfig.suspend();
return <h1 style={{ color: accentColor }}>Hello world</h1>;
};
Generated using TypeDoc
Create a suspending function that will cache the result of the function call. This function will be called only once, with no arguments, and the result will be cached.