Skip to content

Add context as second parameter for the mutation function - #7343

Closed
asermax wants to merge 3 commits into
TanStack:mainfrom
asermax:feature/mutation-function-context
Closed

Add context as second parameter for the mutation function#7343
asermax wants to merge 3 commits into
TanStack:mainfrom
asermax:feature/mutation-function-context

Conversation

@asermax

Copy link
Copy Markdown

This PR adds a context that's passed as the second parameter to the mutationFn in a mutation. This change allows access to the mutation's meta (similar to query functions), which I find useful for passing in configurations (similarly as the case mentioned in #7045 (comment)). I've also included the mutationKey in the context, since it came up in a similar discussion #3504.

While this context could eventually include other information, I kept this initial contribution small and simple as to not get all tangled up with all the typing 😅

@vercel

vercelBot commented Apr 28, 2024

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
NameStatusPreviewCommentsUpdated (UTC)
query⬜️ Ignored (Inspect)Visit PreviewJun 22, 2024 4:07am

@github-actionsgithub-actionsBot added documentation Improvements or additions to documentation package: query-core labels Apr 28, 2024
@codesandbox-ci

codesandbox-ciBot commented Apr 28, 2024

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a750914:

SandboxSource
@tanstack/query-example-angular-basicConfiguration
@tanstack/query-example-react-basic-typescriptConfiguration
@tanstack/query-example-solid-basic-typescriptConfiguration
@tanstack/query-example-svelte-basicConfiguration
@tanstack/query-example-vue-basicConfiguration

@asermax
asermaxforce-pushed the feature/mutation-function-context branch from f60c661 to 8905437CompareMay 20, 2024 15:11
@asermax
asermaxforce-pushed the feature/mutation-function-context branch from 8905437 to a750914CompareJune 22, 2024 04:06
@ATypescriptEnjoyer

Copy link
Copy Markdown

It'd be really cool to get this in 🙏 I use the meta for accessing bearer tokens which works for useQuery but obviously not useMutation

@DavidReinberger

DavidReinberger commented May 2, 2025

Copy link
Copy Markdown

We'd also really like to get this in, to access ky client in queries/mutations without the workaround mentioned here.

@TkDodo

Copy link
Copy Markdown
Collaborator

I would want to consolidate the efforts in this PR please:

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentationImprovements or additions to documentationpackage: query-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@asermax@ATypescriptEnjoyer@DavidReinberger@TkDodo