Skip to content

Commit

Permalink
types: allow passing function as Data for `useSWRSubscriptionOption…
Browse files Browse the repository at this point in the history
…s` (#2551)

feat: allow passing function as `Data` for `useSWRSubscriptionOptions`
  • Loading branch information
promer94 committed Apr 10, 2023
1 parent 540a449 commit 1f71783
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion subscription/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export const subscription = (<Data = any, Error = any>(useSWRNext: SWRHook) =>
const [, set] = createCacheHelper<Data>(cache, subscriptionKey)
const refCount = subscriptions.get(subscriptionKey) || 0

const next = (error?: Error | null, data?: Data) => {
const next: SWRSubscriptionOptions<Data, Error>['next'] = (
error,
data
) => {
if (error !== null && typeof error !== 'undefined') {
set({ error })
} else {
Expand Down
4 changes: 2 additions & 2 deletions subscription/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Key, SWRConfiguration } from 'swr'
import type { Key, SWRConfiguration, MutatorCallback } from 'swr'

export type SWRSubscriptionOptions<Data = any, Error = any> = {
next: (err?: Error | null, data?: Data) => void
next: <T = Data>(err?: Error | null, data?: Data | MutatorCallback<T>) => void
}

export type SWRSubscription<
Expand Down

0 comments on commit 1f71783

Please sign in to comment.