Mutation transformation best practices
Let's say I have a mutate hook that saves a message via a form.
This form has 2 fields, a text field (subject) and a textarea (message).
I need to do some transformation based on conditions prior to sending this payload.
Is it better to:
1. Transform the data at the form level before reaching the mutation hook
2. Transform the data directly in the mutation hook (possibly with onMutate)
?
2 Replies
extended-salmon•17mo ago
I suggest doing it in the mutationFn which is the interface between the form and the api
quickest-silver•17mo ago
I personally like doing it in the
handleSubmit portion because what is cached in the RQ devtools is a better representation of my payload