@croct/plug-react
Version:
React components and hooks to plug your React applications into Croct.
24 lines (21 loc) • 1.67 kB
TypeScript
import { VersionedSlotMap, VersionedSlotId, SlotContent } from '@croct/plug/slot';
import { JsonObject } from '@croct/plug/sdk/json';
import { FetchOptions } from '@croct/plug/plug';
import { FetchResponseOptions, FetchResponse as FetchResponse$1 } from '@croct/sdk/contentFetcher';
import { Optional } from '@croct/sdk/utilityTypes';
type FetchResponse<P = JsonObject, O = FetchResponseOptions> = Optional<FetchResponse$1<P, O>, 'metadata'>;
type UseContentOptions<I, F> = FetchOptions<F> & {
initial?: I;
cacheKey?: string;
expiration?: number;
staleWhileLoading?: boolean;
};
type UseContentHook = {
<P extends JsonObject, I = P, F = P, O extends FetchResponseOptions = FetchResponseOptions>(id: keyof VersionedSlotMap extends never ? string : never, options?: O & UseContentOptions<I, F>): FetchResponse<P | I | F, O>;
<S extends VersionedSlotId, O extends FetchResponseOptions = FetchResponseOptions>(id: S, options?: O & UseContentOptions<never, never>): FetchResponse<SlotContent<S>, O>;
<I, S extends VersionedSlotId, O extends FetchResponseOptions = FetchResponseOptions>(id: S, options?: O & UseContentOptions<I, never>): FetchResponse<SlotContent<S> | I, O>;
<F, S extends VersionedSlotId, O extends FetchResponseOptions = FetchResponseOptions>(id: S, options?: O & UseContentOptions<never, F>): FetchResponse<SlotContent<S> | F, O>;
<I, F, S extends VersionedSlotId, O extends FetchResponseOptions = FetchResponseOptions>(id: S, options?: O & UseContentOptions<I, F>): FetchResponse<SlotContent<S> | I | F, O>;
};
declare const useContent: UseContentHook;
export { type FetchResponse, type UseContentOptions, useContent };