UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

23 lines (22 loc) 1.27 kB
import { type ReactElement, type ReactNode } from "react"; import type { Endpoint } from "../api/endpoint/Endpoint.js"; import type { APIProvider } from "../api/provider/APIProvider.js"; import type { EndpointStore } from "../api/store/EndpointStore.js"; import type { Nullish } from "../util/null.js"; export interface APIContext<P, R> { /** Get an `EndpointStore` for the specified endpoint/payload in the current `APIProvider` context. */ useAPI<PP extends P, RR extends R>(this: void, endpoint: Endpoint<PP, RR>, payload: PP): EndpointStore<PP, RR>; useAPI<PP extends P, RR extends R>(this: void, endpoint: Nullish<Endpoint<PP, RR>>, payload: PP): EndpointStore<PP, RR> | undefined; /** The `<APIContext>` wrapper to give your React components access to this API provider. */ readonly APIContext: ({ children }: { children: ReactNode; }) => ReactElement; } /** * Create an API context. * - Allows React elements to call `useAPI()` to access endpoint stores in an API provider. * - Each mounted `APIContext` gets its own in-memory store cache. * * @todo Use and integreate our `EndpointCache` functionality and use it in this. */ export declare function createAPIContext<P, R>(provider: APIProvider<P, R>): APIContext<P, R>;