Skip to content

feat: add extra arg in onSuccess, onError #2286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
28 changes: 0 additions & 28 deletions .github/workflows/test-canary.yml

This file was deleted.

90 changes: 0 additions & 90 deletions .github/workflows/trigger-release.yml

This file was deleted.

4 changes: 2 additions & 2 deletions src/mutation/index.ts
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ const mutation = (<Data, Error>() =>
startTransition(() =>
setState({ data, isMutating: false, error: undefined })
)
options.onSuccess?.(data as Data, serializedKey, options)
options.onSuccess?.(data as Data, serializedKey, options, arg)
}
return data
} catch (error) {
@@ -91,7 +91,7 @@ const mutation = (<Data, Error>() =>
startTransition(() =>
setState({ error: error as Error, isMutating: false })
)
options.onError?.(error as Error, serializedKey, options)
options.onError?.(error as Error, serializedKey, options, arg)
if (options.throwOnError) {
throw error as Error
}
6 changes: 4 additions & 2 deletions src/mutation/types.ts
Original file line number Diff line number Diff line change
@@ -37,14 +37,16 @@ export type SWRMutationConfiguration<
key: string,
config: Readonly<
SWRMutationConfiguration<Data, Error, SWRMutationKey, ExtraArg, SWRData>
>
>,
extraArg: ExtraArg
) => void
onError?: (
err: Error,
key: string,
config: Readonly<
SWRMutationConfiguration<Data, Error, SWRMutationKey, ExtraArg, SWRData>
>
>,
extraArg: ExtraArg
) => void
}