diff --git a/infinite/index.ts b/infinite/index.ts index 828f696a0c..eb072bda9c 100644 --- a/infinite/index.ts +++ b/infinite/index.ts @@ -7,7 +7,8 @@ import useSWR, { SWRHook, MutatorCallback, Middleware, - BareFetcher + BareFetcher, + MutatorOptions } from 'swr' import { useIsomorphicLayoutEffect } from '../src/utils/env' @@ -176,14 +177,15 @@ export const infinite = ((useSWRNext: SWRHook) => | [undefined | Data[] | Promise | MutatorCallback] | [ undefined | Data[] | Promise | MutatorCallback, - boolean + boolean | MutatorOptions | undefined ] ) => { - const data = args[0] - + const [data, _opts] = args + // When passing as a boolean, it's explicitly used to disable/enable // revalidation. - const options = typeof args[1] === 'boolean' ? {revalidate: args[1]} : args[1] || {} + const options = + typeof _opts === 'boolean' ? { revalidate: _opts } : _opts || {} // Default to true. const shouldRevalidate = options.revalidate !== false @@ -202,7 +204,7 @@ export const infinite = ((useSWRNext: SWRHook) => } } - return args.length ? swr.mutate(data, shouldRevalidate) : swr.mutate() + return args.length ? swr.mutate(data, options) : swr.mutate() }, // swr.mutate is always the same reference // eslint-disable-next-line react-hooks/exhaustive-deps