Skip to content
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

feat: add extra arg in onSuccess, onError #2286

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions mutation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ const mutation = (<Data, Error>() =>
// If it's reset after the mutation, we don't broadcast any state change.
if (ditchMutationsUntilRef.current <= mutationStartedAt) {
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) {
// If it's reset after the mutation, we don't broadcast any state change
// or throw because it's discarded.
if (ditchMutationsUntilRef.current <= mutationStartedAt) {
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
}
Expand Down
6 changes: 4 additions & 2 deletions mutation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ export type SWRMutationConfiguration<
key: string,
config: Readonly<
SWRMutationConfiguration<Data, Error, ExtraArg, SWRMutationKey, SWRData>
>
>,
extraArg: any
Lee-sungheon marked this conversation as resolved.
Show resolved Hide resolved
) => void
onError?: (
err: Error,
key: string,
config: Readonly<
SWRMutationConfiguration<Data, Error, ExtraArg, SWRMutationKey, SWRData>
>
>,
extraArg: any
Lee-sungheon marked this conversation as resolved.
Show resolved Hide resolved
) => void
}

Expand Down