Skip to content

Commit

Permalink
Update swr infinite mutate to take mutator options
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjeev40 committed May 2, 2022
1 parent b6f4781 commit 2d7078f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions infinite/index.ts
Expand Up @@ -7,7 +7,8 @@ import useSWR, {
SWRHook,
MutatorCallback,
Middleware,
BareFetcher
BareFetcher,
MutatorOptions
} from 'swr'

import { useIsomorphicLayoutEffect } from '../src/utils/env'
Expand Down Expand Up @@ -176,14 +177,15 @@ export const infinite = (<Data, Error>(useSWRNext: SWRHook) =>
| [undefined | Data[] | Promise<Data[]> | MutatorCallback<Data[]>]
| [
undefined | Data[] | Promise<Data[]> | MutatorCallback<Data[]>,
boolean
boolean | MutatorOptions<Data[]> | 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
Expand All @@ -202,7 +204,7 @@ export const infinite = (<Data, Error>(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
Expand Down

0 comments on commit 2d7078f

Please sign in to comment.