Skip to content
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

Recommended changes to getting started guide #228

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions apps/web/app/routes/get-started.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export default function Component() {
<p>
Compose a zod schema that will be used in your action, mutation
function, form generation, server-side validation, and client-side
validation.
validation. You can do this in a route where you'll be submitting form.
</p>
<Code>{schemaCode}</Code>
<SubHeading>Create your mutation</SubHeading>
Expand All @@ -247,17 +247,26 @@ export default function Component() {
<p>
Domain Functions will parse the request&apos;s <em>formData</em> and
perform the mutation only if everything is valid. If something goes bad,
it will return structured error messages for us.
it will return structured error messages for us. You can also put this
in the route where you'll be submitting a form.
Copy link
Contributor

@gustavoguichard gustavoguichard Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is not a good practice as domain functions usually have server side code.
I use to put my schemas in a app/domain/some-domain folder so they can be used in their related domain function. I also keep my domain functions away from the route as there's no need (and often there are problems) to send that code to the client bundle.

Now that we have route folders in Remix v2 you could create those functions in separate files under that route's folder but it is important to make sure you only use them in either loaders or actions so it won't be sent to the client.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'm writing short mutations inline in the formAction, but worth clarifying! Let me update the patch.

</p>
<Code>{mutationCode}</Code>
<SubHeading>Create your action</SubHeading>
<p>
Create an action in the route where you'll be submitting a form, and
return a <em>formAction</em> from it.
</p>
<p>
If the mutation is successful, <em>formAction</em> will redirect to{' '}
<em>successPath</em>. If not, it will return <em>errors</em> and{' '}
<em>values</em> to pass to <em>Form</em>.
</p>
<Code>{actionCode}</Code>
<SubHeading>Create a basic form</SubHeading>
<p>
Now it's time to head down into the component and return a <em>Form</em>
.
</p>
<p>
If you don&apos;t want any custom UI in the form, you can render{' '}
<em>Form</em> without <em>children</em> and it will generate all the
Expand Down