-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add transformValues option to performMutation and formAction #110
Conversation
✅ Deploy Preview for remix-forms ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it! Then I can use a pattern I'm used to - which I call: "let zod handle the params"
export async function action({ request, params }: ActionArgs) {
return formAction({
request,
mutation,
schema,
additionalInput: params,
})
}
That said I'm not sure about the naming... it feels to me we could come up with some better name but I'm out of ideas right now 😅
|
||
const mutation = makeDomainFunction(mutationSchema)(async (values) => values) | ||
|
||
export const action: ActionFunction = async ({ request }) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use ActionArgs
here for better type inference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only if we want to promote Remix + TS best practices on the docs, which I think might be valid. But we don't need it with Remix Forms, because Remix Forms is the one that calls useActionData
and makes sure the typing is correct. We'll almost never call useActionData<typeof action>
when using Remix Forms.
For now, I've been preferring the shorter code that arrow functions give us. I already feel there is a lot of code to read in the examples, so I take every opportunity I have to have fewer lines of code :)
But I'm very open to changing this if you really care about promoting better Remix TS practices on the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, ship it
@diogob suggested a broader API with a |
Cool! It reminds me of Zod preprocess, another possible name but I like the idea, opens up for more possibilities |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Check out the new "Transform values" example for understanding what the functionality does.
The primary use case is to pass URL input to mutations without having to add a hidden field to the form. Let's say we're at
/users/$userId/edit
. BeforetransformValues
, we'd have to add theuserId
field to the form schema, get the value from the params, pass it to the Form'svalues
prop, and mark the userId field as hidden.Now we can leave the
userId
out of the form schema altogether, add it only to the mutation schema, and passtransformValues: (values) => ({ ...params, ...values })
to our formAction or performMutation.