Default mutation function using key #7442
Unanswered
honzahruby
asked this question in
Ideas
Replies: 3 comments 2 replies
-
@TkDodo any idea why it's so? 🙏 |
Beta Was this translation helpful? Give feedback.
0 replies
-
we don't pass anything to the mutationFn because the mutationFn takes |
Beta Was this translation helpful? Give feedback.
1 reply
-
Sorry for pinging you again @TkDodo, I've put together a simple code example to better explain what I'm trying to achieve. Basically going from this (where the key is optional) const useDeleteUser = () =>
useMutation({
mutationKey: ['users', 'delete'],
mutationFn: async (id: string) => apiClient.users.delete(id),
}); to this const reactQueryClient = new QueryClient({
defaultOptions: {
mutations: {
mutationFn: async (variables, { mutationKey: [controller, method] }) => apiClient[controller][method](variables),
},
},
});
const useDeleteUser = () =>
useMutation({
mutationKey: ['users', 'delete'],
}); which mimics what's already possible for queries. Is it something you would consider adding? 🙏 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Similar to the default query function, we'd love the ability for the default mutation function to access the mutation key. Currently, it can only access the variables passed by the user.
Is it a conscious decision, given the mutation key is optional, while in queries it's required? Or is it something to consider adding? 🙏
Beta Was this translation helpful? Give feedback.
All reactions