Replies: 2 comments 2 replies
-
Yes you are missing something: used like so: ` const onSubmit = (data: SummonTravelArrangementFormData) => {
}; I am sharing an improper for the SWR cache because the ID is passed inside the trigger function, but you can easily add a random id to the key, like |
Beta Was this translation helpful? Give feedback.
-
Yeah, the hook useSWRMutation lacks many functionalities. I recommend creating your own implementation of the hook using a pattern similar to |
Beta Was this translation helpful? Give feedback.
-
The way
useSWRMutation
works makes it impossible to have properly typed conditional usages.Take a REST endpoint:
PUT books/:id
.If I wanted to create a reusable hook to update a book I have to do this:
This means I can't use
useUpdateBookMutation
when I don't have an id always present.If the
useSWRMutation
interface allowed to pass the url parameter as part of the trigger callback though, this would be trivial.Is this impossible to achieve with SWR or am I missing something obvious?
Beta Was this translation helpful? Give feedback.
All reactions