mutationFn parameter in useMutation #1070
-
Hi there 👋 Firstly thanks for your amazing library! In my scenario, every mutationFns are quite similar, they almost post requests with different payload and api path. So I'm wondering do we consider adding a global mutationFn like queryFn, I only need to pass the api path to useMutation. or what can I do to avoid repeating code? like this:
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I don't see that much overhead / repeating code in your example, but if you want, most abstractions can be handled with custom hooks:
if error handling is all the same, you can do that in that hook. usage:
I don't see a way of avoiding calling the hook, which will give you a function that you can invoke eventually (later). But I've also never had the need to... Or did you have something totally different in mind? |
Beta Was this translation helpful? Give feedback.
I don't see that much overhead / repeating code in your example, but if you want, most abstractions can be handled with custom hooks:
if error handling is all the same, you can do that in that hook. usage:
I don't see a way of avoiding calling the hook, which will give you a function that you can invoke eventually (later). But I've also never had the need to...
Or did you have something totally different in mind?