Skip to content

Commit

Permalink
put back unrelated changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lendihop committed Feb 13, 2025
1 parent defa130 commit 0e0137b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/lib/swr/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import useSWR, { Key, SWRConfiguration, SWRResponse } from 'swr';
import useSWR, { Key, SWRConfiguration } from 'swr';
import { FetcherResponse } from 'swr/_internal';

type Fetcher<Data = unknown, SWRKey extends Key = Key> = (arg: SWRKey) => FetcherResponse<Data>;

/** Fetcher must not return (awaited) `undefined` value - results in endless fetching. */
export const useTypedSWR = <Data, Error = any, SWRKey extends Key = Key>(
key: SWRKey,
fetcher: Fetcher<Data, SWRKey> | null,
config?: SWRConfiguration<Data, Error, Fetcher<Data, SWRKey>>
): SWRResponse<Data, Error> => useSWR(key, fetcher, config);
) => useSWR(key, fetcher, config);

/** Fetcher must not return (awaited) `undefined` value - results in endless fetching. */
export const useRetryableSWR = <Data, Error = any, SWRKey extends Key = Key>(
key: SWRKey,
fetcher: Fetcher<Data, SWRKey> | null,
config?: SWRConfiguration<Data, Error, Fetcher<Data, SWRKey>>
): SWRResponse<Data, Error> => useSWR(key, fetcher, { errorRetryCount: 2, ...config });
) => useSWR(key, fetcher, { errorRetryCount: 2, ...config });

0 comments on commit 0e0137b

Please sign in to comment.