import { Context, ComponentType, ReactNode, Dispatch, SetStateAction } from "react"; /** * {@link IdContextProviderProps.id | Provider id} type. * Using the id `null` specifies the closest Provider. */ type Id = string | number | symbol | null; /** @internal */ interface Environment { has(key: Id): boolean; get(key: Id): T | undefined; [Symbol.iterator](): IterableIterator<[ Id, T ]>; } interface IdContextConsumerProps { /** * The {@link IdContextProvider} to use * @default null */ id?: Id; children: (value: T) => ReactNode; } type IdContextConsumer = ComponentType>; interface IdContextProviderProps { /** * The value to provide */ value: T; /** * The key that identifies the {@link IdContextProvider} to be consumed * @default null */ id?: Id; /** * @default null */ children?: ReactNode; } type IdContextProvider = ComponentType>; /** * A privately scoped unique symbol for accessing {@link IdContext} internal {@link Environment} * @internal */ declare const kEnvironment: unique symbol; /** * A Context with support for multiple keyed values */ interface IdContext { Consumer: IdContextConsumer; Provider: IdContextProvider; /** @internal */ [kEnvironment]: Context>; } /** * Creates a keyed Context allowing multiple nested Providers to be accessible in the same scope. * @param defaultValue the value consumed if no {@link IdContextProvider} is in scope and the * {@link IdContextConsumerProps.id | consumer `id`} is `null` */ declare function createIdContext(defaultValue: T): IdContext; /** * Consumes a value from an {@link IdContextProvider} * @param context the {@link IdContext} to use * @param id the {@link IdContextProviderProps.id | IdContextProvider id} to use */ declare function useIdContext(context: IdContext, id?: Id): T; interface ServiceConsumerProps { /** * The {@link ServiceProvider} to use * @default null */ id?: Id; children: (value: TResponse, setState: Dispatch>) => ReactNode; } type ServiceConsumer = ComponentType>; /** * The type of reset function when initialState updates */ type Reset = (prevState: S, newInitialState: S) => S; interface ServiceProviderProps { /** * The request passed to {@link createService | handler} for fetching an asynchronous resource. */ request: TRequest; /** * The key that identifies the {@link ServiceProvider} to be consumed * @default null */ id?: Id; /** * @default null */ children?: ReactNode; /** * The fallback to render if any children are suspended. * If the fallback is `null`, `undefined`, or omitted, then a Suspense * component must be inserted elsewhere between the * {@link ServiceProvider | Provider} and {@link ServiceConsumer | Consumer}. * @default null */ fallback?: NonNullable | null; /** * The reset function when {@link ServiceProviderProps.request | request} updates */ reset?: Reset; } type ServiceProvider = ComponentType>; /** * The type of asynchronous function for fetching data */ type Handler = (request: TRequest, id: Id) => PromiseLike; /** * A privately scoped unique symbol for accessing {@link Service} internal {@link Resource} * @internal */ declare const kResource: unique symbol; /** * A Suspense integration for providing asynchronous data through a Context API */ interface Service { Consumer: ServiceConsumer; Provider: ServiceProvider; /** @internal */ [kResource]: IdContext<[ () => TResponse, Dispatch> ]>; } /** * Creates a Service Context for providing asynchronous data * @param handler the asynchronous function for fetching data */ declare function createService(handler: Handler): Service; /** * Synchronously consumes a stateful response from a {@link ServiceProvider} * @param service the {@link Service} to use * @param id the {@link ServiceProviderProps.id | ServiceProvider id} to use */ declare function useServiceState(service: Service, id?: Id): [ TResponse, Dispatch> ]; /** * Synchronously consumes a response from a {@link ServiceProvider} * @param service the {@link Service} to use * @param id the {@link ServiceProviderProps.id | ServiceProvider id} to use */ declare function useService(service: Service, id?: Id): TResponse; /** * A stateful value and a function to update it */ type State = [ T, Dispatch> ]; interface StateConsumerProps { /** * The {@link StateProvider} to use * @default null */ id?: Id; children: (value: T, setState: Dispatch>) => ReactNode; } type StateContextConsumerProps = StateConsumerProps; type StateContextConsumer = ComponentType>; interface StateContextProviderProps { /** * The initial value to provide */ value: T; /** * The key that identifies the {@link StateContextProvider} to be consumed * @default null */ id?: Id; /** * @default null */ children?: ReactNode; /** * The reset function when {@link StateProviderProps.value | value} updates */ reset?: Reset; } type StateContextProvider = ComponentType>; /** * A privately scoped unique symbol for accessing {@link StateContext} internal {@link State} * @internal */ declare const kState: unique symbol; /** * A State Context with support for multiple keyed values */ interface StateContext { Consumer: StateContextConsumer; Provider: StateContextProvider; /** @internal */ [kState]: IdContext>; } /** * Creates a State Context for providing a stateful value and a function to update it. * @param defaultValue the value consumed if no {@link StateContextProvider} is in scope and the * {@link StateContextConsumerProps.id | consumer `id`} is `null` */ declare function createStateContext(defaultValue: T): StateContext; /** * Consumes a stateful value from a {@link StateContextProvider}, and a function to update it * @param context the {@link StateContext} to use * @param id the {@link StateContextProviderProps.id | StateContextProvider id} to use */ declare function useStateContext(context: StateContext, id?: Id): State; export { Id, IdContextConsumer, IdContextConsumerProps, IdContextProvider, IdContextProviderProps, IdContext, createIdContext, useIdContext, ServiceConsumer, ServiceConsumerProps, ServiceProvider, ServiceProviderProps, Service, Handler, createService, useService, useServiceState, State, StateContextConsumer, StateContextConsumerProps, StateContextProvider, StateContextProviderProps, StateContext, createStateContext, useStateContext, Reset }; //# sourceMappingURL=suspense-service.d.ts.map