All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.subscription.index.d.mts Maven / Gradle / Ivy

The newest version!
import { MutatorCallback, Key, SWRConfiguration, Middleware } from 'swr/_internal';

type SWRSubscriptionOptions = {
    next: (err?: Error | null, data?: Data | MutatorCallback) => void;
};
type SWRSubscription = SWRSubKey extends () => infer Arg | null | undefined | false ? (key: Arg, { next }: SWRSubscriptionOptions) => void : SWRSubKey extends null | undefined | false ? never : SWRSubKey extends infer Arg ? (key: Arg, { next }: SWRSubscriptionOptions) => void : never;
type SWRSubscriptionResponse = {
    data?: Data;
    error?: Error;
};
type SWRSubscriptionHook = (key: SWRSubKey, subscribe: SWRSubscription, config?: SWRConfiguration) => SWRSubscriptionResponse;

declare const subscription: Middleware;
/**
 * A hook to subscribe a SWR resource to an external data source for continuous updates.
 * @experimental This API is experimental and might change in the future.
 * @example
 * ```jsx
 * import useSWRSubscription from 'swr/subscription'
 *
 * const { data, error } = useSWRSubscription(key, (key, { next }) => {
 *   const unsubscribe = dataSource.subscribe(key, (err, data) => {
 *     next(err, data)
 *   })
 *   return unsubscribe
 * })
 * ```
 */
declare const useSWRSubscription: SWRSubscriptionHook;

export { type SWRSubscription, type SWRSubscriptionHook, type SWRSubscriptionOptions, type SWRSubscriptionResponse, useSWRSubscription as default, subscription };




© 2015 - 2024 Weber Informatics LLC | Privacy Policy