TanStack / query

🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
https://tanstack.com/query
MIT License
40.1k stars 2.69k forks source link

Add context as second parameter for the mutation function #7343

Open asermax opened 2 weeks ago

asermax commented 2 weeks ago

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 https://github.com/TanStack/query/discussions/7045#discussioncomment-9151048). 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 :sweat_smile:

vercel[bot] commented 2 weeks ago

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

1 Ignored Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **query** | ⬜️ Ignored ([Inspect](https://vercel.com/tanstack/query/2KATA5K1kAnuzmzVZjDMqrd2zdbs)) | [Visit Preview](https://query-git-fork-asermax-feature-mutation-functio-f555af-tanstack.vercel.app) | | Apr 28, 2024 2:59am |
codesandbox-ci[bot] commented 2 weeks ago

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 f60c661e57941b072c455edd7459d9e7bddb3466:

Sandbox Source
@tanstack/query-example-angular-basic Configuration
@tanstack/query-example-react-basic-typescript Configuration
@tanstack/query-example-solid-basic-typescript Configuration
@tanstack/query-example-svelte-basic Configuration
@tanstack/query-example-vue-basic Configuration