Skip to content

Commit

Permalink
Form vs useFetcher v2
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsoderlund committed Oct 1, 2024
1 parent e8cf131 commit e9ce559
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions Development/JavaScript/Remix.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,29 @@ Blockers and navigate away:

### Form vs useFetcher

1. **`<Form>`**:
https://remix.run/docs/en/main/discussion/form-vs-fetcher

(All: triggers server-side `action` + `loader` once)

1. **HTML `<form>`**:
- Normally: avoid
- Traditional form submission with navigation to other route and/or full-page reload.
- Best for simple or multi-page forms.
2. **`fetcher.Form`**:
- When a form element is suitable, but not navigation to other route or full-page reload.
- For AJAX-style form interactions, with a form element.
- Triggers action + loader, **renders on server** + client (2 times)
2. **Remix `<Form>`**:
- The default form usage in Remix
- No full page reload, but `loader` runs
- Can use `redirect` in loader
- Renders client 6 times (no render on server)
3. **Remix `useFetcher` with `fetcher.Form`**:
- When a `form` element is suitable, but not navigation to other route or full-page reload.
- Renders client 6 times, `useActionData` returns undefined, instead action data in fetcher.data
- For AJAX-style form interactions, with a `form` element.
- No full-page reload; stays on the same page and updates specific components.
3. **`fetcher.submit`**:
- When a form element is not suitable.
4. **Remix `useFetcher` with `fetcher.submit`**:
- When a `form` element is not suitable.
- Behaves similarly as `fetcher.Form` above
- For programmatic control over form submission.
- Best for scenarios like conditional submissions or button clicks outside of the form element.
- Best for scenarios like conditional submissions or button clicks outside of the `form` element.

## Syntax

Expand Down

0 comments on commit e9ce559

Please sign in to comment.