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

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

There is a newer version: 2.2.5
Show newest version
import { Key, SWRConfiguration, Middleware } from 'swr';

type SWRSubscription = (key: Key, { next }: {
    next: (err?: Error | null, data?: Data) => void;
}) => () => void;
type SWRSubscriptionResponse = {
    data?: Data;
    error?: Error;
};
type SWRSubscriptionHook = (key: Key, 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 { SWRSubscription, SWRSubscriptionHook, SWRSubscriptionResponse, useSWRSubscription as default, subscription };




© 2015 - 2024 Weber Informatics LLC | Privacy Policy