Remix v2 Forms & Mutations
Canonical mutation primitives for the @remix-run/react@^2 route-module
framework. A correct Remix v2 mutation is: a <Form method="post"> (or
<fetcher.Form>), an action that parses request.formData() and returns
either redirect(...) or json(...), and UI that reads useActionData()
(or fetcher.data) for errors plus useNavigation() (or fetcher.state)
for pending state. Anything that bypasses this loop — fetch(), raw
<form>, e.preventDefault() + client state — silently sacrifices
revalidation, progressive enhancement, and race-safe transitions.
Quick Reference
<Form> + action:
import { json, redirect, type ActionFunctionArgs } from "@remix-run/node";
import { Form, useActionData, useNavigation } from "@remix-run/react";
export async function action({ request }: ActionFunctionArgs) {
const form = await request.formData();
const email = String(form.get("email") ?? "");
if (!email.includes("@")) return json({ errors: { email: "Invalid" } }, { status: 400 });
await createUser({ email });
return redirect("/dashboard");
}
export default function Signup() {
const actionData = useActionData<typeof action>();
const nav = useNavigation();
const busy = nav.state !== "idle" && nav.formAction === "/signup";
return (
<Form method="post" replace>
<input name="email" type="email" />
{actionData?.errors?.email ? <em>{actionData.errors.email}</em> : null}
<button disabled={busy}>{busy ? "Signing up..." : "Sign Up"}</button>
</Form>
);
}
Primitives
| Name |
Purpose |
<Form> from @remix-run/react |
Navigating, progressively-enhanced form that posts to a route action and triggers full-page revalidation |
<Form navigate={false}> |
Shorthand for "post via fetcher; do not navigate." Equivalent to <fetcher.Form> without holding a fetcher ref — useful when you only need pending state, not a programmatic handle |
useFetcher() |
Non-navigating submission channel for inline mutations, list rows, popovers — same revalidation, no URL change |
useFetchers() |
Read-only array of all in-flight fetcher states across the app. Use for global pending indicators (top-bar loader) without prop drilling. No Form/submit/load methods on the returned items — just formData, state, etc. |
useNavigation() |
Observes page-level navigation; the source of truth for <Form> pending state |
useSubmit() |
Programmatic submission (onChange autosave, keyboard shortcuts). Accepts HTMLFormElement, FormData, plain object (form-encoded), or plain object encoded as JSON via { encType: "application/json" } |
useActionData<typeof action>() |
Read the most recent action result for the current route |
State transitions:
useNavigation().state: idle → submitting → loading → idle for non-GET
form submissions; idle → loading → idle for GET navigation.
useFetcher().state: idle → submitting → loading → idle.
Asymmetry: useNavigation skips submitting for GET navigations; useFetcher does NOT — only fetcher.load() skips it. <fetcher.Form method='get'> and fetcher.submit(..., {method:'get'}) both transition through submitting.
Key Patterns
<Form> for navigation, useFetcher for in-place
<Form> changes the URL, adds history, and revalidates all loaders.
useFetcher does the same revalidation but stays on the current URL.
Each useFetcher() call returns an independent submission channel, so
two rows submitting at once do not share pending state.
Intent pattern for multiple actions on one route
One action, switch on formData.get("intent"), distinct
<button name="intent" value="..."> per operation. Only the clicked
submit button's name=value lands in the body. See
references/intent-actions.md.
Optimistic UI from formData
fetcher.formData and navigation.formData are populated synchronously
on submit and cleared at idle. Read directly each render; never mirror
into local React state. See
references/optimistic-ui.md.
File uploads need encType="multipart/form-data"
Without it, request.formData() strips file data and you get the
filename string instead of a File. Parse with
unstable_parseMultipartFormData and a bounded upload handler. The
unstable_ prefix is permanent in v2. See
references/uploads.md.
Gates (decision sequencing)
Answer in order. Pass means the condition is true; pick the API
on the same line and stop.
<Form> vs useFetcher
- Does the URL need to change after the mutation (creating a record
and routing to
/records/:id, deleting and going back to a list,
multi-step flow)?
- Pass →
<Form method="post"> + redirect(...) from the action. Stop.
- Fail → Step 2.
- Is this a mutation against a row, cell, toggle, or sub-section while
the user stays on the same page (favorite, like, increment quantity,
inline edit)?
- Pass →
useFetcher() with <fetcher.Form>. Stop.
- Fail → Step 3.
- Is this loading data outside of normal navigation (popover content,
combobox results, prefetch)?
- Pass →
fetcher.load(href). Stop.
- Fail → Default to
<Form>. Navigation is the conservative
choice — revalidation and history work out of the box.
Hard rule: never reach for fetch() or axios for in-app mutations
against your own Remix routes. That bypasses the action lifecycle and
skips loader revalidation.
useNavigation vs useFetcher.state for pending state
- Is the pending indicator global (page spinner in root, top-bar
loading bar)?
- Pass →
useNavigation() in root.tsx
(navigation.state !== "idle"). Stop.
- Fail → Step 2.
- Was the mutation made with
useFetcher?
- Pass → Use that fetcher's
fetcher.state. useNavigation()
will NOT reflect fetcher activity. Stop.
- Fail → Step 3.
- Is the indicator scoped to one row/button inside a list where each
row has its own fetcher?
- Pass → Use the per-row
fetcher.state (or look up by key via
useFetchers()) so other rows do not flicker. Stop.
- Fail → Step 4.
- Is the indicator scoped to the form just submitted via
<Form>?
- Pass →
useNavigation() AND check
navigation.formAction === "/expected-path" so unrelated navigations
don't trigger your local spinner. Stop.
- Fail → Step 5.
- Need to render an optimistic value?
- Pass → Read
navigation.formData?.get("field") (page form) or
fetcher.formData?.get("field") (fetcher) — both are populated
while state !== "idle". Stop.
Additional Documentation
<Form> component: See references/form.md for
<Form> vs native <form> vs fetch(), progressive enhancement,
redirect-after-success, and validation error display via useActionData.
useFetcher: See references/fetcher.md for
inline mutations, list operations, popovers, fetcher.state,
fetcher.data, fetcher.Form, fetcher.submit, fetcher.load.
- Optimistic UI: See
references/optimistic-ui.md for
fetcher.formData and useNavigation.formData, when to apply, and
reverting on failure.
- File uploads: See references/uploads.md
for
unstable_parseMultipartFormData,
unstable_createMemoryUploadHandler,
unstable_createFileUploadHandler, and bounded handlers.
- Intent-based actions: See
references/intent-actions.md for
multiple actions on one route via the FormData
intent field.
Comparison
| Concern |
<Form> |
useFetcher |
Native <form> |
fetch() |
| URL change / history entry |
Yes |
No |
Yes (hard nav) |
No |
| Works without JS |
Yes |
Yes |
Yes |
No |
| Revalidates loaders |
Yes |
Yes |
Yes (hard reload) |
No |
| Pending state hook |
useNavigation() |
fetcher.state |
None |
Manual |
| Optimistic input source |
navigation.formData |
fetcher.formData |
None |
Manual |
| In-app mutation use case |
Create / delete / multi-step |
Inline / row / toggle |
External targets only |
Never for own routes |
1---2name: remix-v2-forms3description: Remix v2 form submissions and mutations. Use when implementing forms, optimistic UI, file uploads, or multi-action routes. Triggers on <Form>, useFetcher, useSubmit, useNavigation for pending state, unstable_parseMultipartFormData, fetcher.formData, intent-based actions, encType multipart.4---5
6# Remix v2 Forms & Mutations
7
8Canonical mutation primitives for the `@remix-run/react@^2` route-module
9framework. A correct Remix v2 mutation is: a `<Form method="post">` (or
10`<fetcher.Form>`), an `action` that parses `request.formData()` and returns
11either `redirect(...)` or `json(...)`, and UI that reads `useActionData()`
12(or `fetcher.data`) for errors plus `useNavigation()` (or `fetcher.state`)
13for pending state. Anything that bypasses this loop — `fetch()`, raw
14`<form>`, `e.preventDefault()` + client state — silently sacrifices
15revalidation, progressive enhancement, and race-safe transitions.
16
17## Quick Reference
18
19**`<Form>` + action**:
20
21```tsx
22import { json, redirect, type ActionFunctionArgs } from "@remix-run/node";
23import { Form, useActionData, useNavigation } from "@remix-run/react";
24
25export async function action({ request }: ActionFunctionArgs) {
26 const form = await request.formData();
27 const email = String(form.get("email") ?? "");
28 if (!email.includes("@")) return json({ errors: { email: "Invalid" } }, { status: 400 });
29 await createUser({ email });
30 return redirect("/dashboard");
31}
32
33export default function Signup() {
34 const actionData = useActionData<typeof action>();
35 const nav = useNavigation();
36 const busy = nav.state !== "idle" && nav.formAction === "/signup";
37 return (
38 <Form method="post" replace>
39 <input name="email" type="email" />
40 {actionData?.errors?.email ? <em>{actionData.errors.email}</em> : null}
41 <button disabled={busy}>{busy ? "Signing up..." : "Sign Up"}</button>
42 </Form>
43 );
44}
45```
46
47## Primitives
48
49| Name | Purpose |
50|---|---|
51| `<Form>` from `@remix-run/react` | Navigating, progressively-enhanced form that posts to a route `action` and triggers full-page revalidation |
52| `<Form navigate={false}>` | Shorthand for "post via fetcher; do not navigate." Equivalent to `<fetcher.Form>` without holding a fetcher ref — useful when you only need pending state, not a programmatic handle |
53| `useFetcher()` | Non-navigating submission channel for inline mutations, list rows, popovers — same revalidation, no URL change |
54| `useFetchers()` | **Read-only** array of all in-flight fetcher states across the app. Use for global pending indicators (top-bar loader) without prop drilling. No `Form`/`submit`/`load` methods on the returned items — just `formData`, `state`, etc. |
55| `useNavigation()` | Observes page-level navigation; the source of truth for `<Form>` pending state |
56| `useSubmit()` | Programmatic submission (onChange autosave, keyboard shortcuts). Accepts `HTMLFormElement`, `FormData`, plain object (form-encoded), or plain object encoded as JSON via `{ encType: "application/json" }` |
57| `useActionData<typeof action>()` | Read the most recent action result for the current route |
58
59State transitions:
60
61- `useNavigation().state`: `idle → submitting → loading → idle` for non-GET
62 form submissions; `idle → loading → idle` for GET navigation.
63- `useFetcher().state`: `idle → submitting → loading → idle`.
64
65**Asymmetry:** `useNavigation` skips `submitting` for GET navigations; `useFetcher` does NOT — only `fetcher.load()` skips it. `<fetcher.Form method='get'>` and `fetcher.submit(..., {method:'get'})` both transition through `submitting`.
66
67## Key Patterns
68
69### `<Form>` for navigation, `useFetcher` for in-place
70
71`<Form>` changes the URL, adds history, and revalidates all loaders.
72`useFetcher` does the same revalidation but stays on the current URL.
73Each `useFetcher()` call returns an independent submission channel, so
74two rows submitting at once do not share pending state.
75
76### Intent pattern for multiple actions on one route
77
78One `action`, switch on `formData.get("intent")`, distinct
79`<button name="intent" value="...">` per operation. Only the clicked
80submit button's `name=value` lands in the body. See
81[references/intent-actions.md](references/intent-actions.md).
82
83### Optimistic UI from `formData`
84
85`fetcher.formData` and `navigation.formData` are populated synchronously
86on submit and cleared at `idle`. Read directly each render; never mirror
87into local React state. See
88[references/optimistic-ui.md](references/optimistic-ui.md).
89
90### File uploads need `encType="multipart/form-data"`
91
92Without it, `request.formData()` strips file data and you get the
93filename string instead of a `File`. Parse with
94`unstable_parseMultipartFormData` and a bounded upload handler. The
95`unstable_` prefix is permanent in v2. See
96[references/uploads.md](references/uploads.md).
97
98## Gates (decision sequencing)
99
100Answer **in order**. **Pass** means the condition is true; pick the API
101on the same line and **stop**.
102
103### `<Form>` vs `useFetcher`
104
1051. **Does the URL need to change after the mutation** (creating a record
106 and routing to `/records/:id`, deleting and going back to a list,
107 multi-step flow)?
108 - **Pass →** `<Form method="post">` + `redirect(...)` from the action. **Stop.**
109 - **Fail →** Step 2.
1102. **Is this a mutation against a row, cell, toggle, or sub-section while
111 the user stays on the same page** (favorite, like, increment quantity,
112 inline edit)?
113 - **Pass →** `useFetcher()` with `<fetcher.Form>`. **Stop.**
114 - **Fail →** Step 3.
1153. **Is this loading data outside of normal navigation** (popover content,
116 combobox results, prefetch)?
117 - **Pass →** `fetcher.load(href)`. **Stop.**
118 - **Fail →** Default to `<Form>`. Navigation is the conservative
119 choice — revalidation and history work out of the box.
120
121Hard rule: never reach for `fetch()` or `axios` for in-app mutations
122against your own Remix routes. That bypasses the action lifecycle and
123skips loader revalidation.
124
125### `useNavigation` vs `useFetcher.state` for pending state
126
1271. **Is the pending indicator global** (page spinner in root, top-bar
128 loading bar)?
129 - **Pass →** `useNavigation()` in `root.tsx`
130 (`navigation.state !== "idle"`). **Stop.**
131 - **Fail →** Step 2.
1322. **Was the mutation made with `useFetcher`?**
133 - **Pass →** Use that fetcher's `fetcher.state`. `useNavigation()`
134 will NOT reflect fetcher activity. **Stop.**
135 - **Fail →** Step 3.
1363. **Is the indicator scoped to one row/button inside a list where each
137 row has its own fetcher?**
138 - **Pass →** Use the per-row `fetcher.state` (or look up by key via
139 `useFetchers()`) so other rows do not flicker. **Stop.**
140 - **Fail →** Step 4.
1414. **Is the indicator scoped to the form just submitted via `<Form>`?**
142 - **Pass →** `useNavigation()` AND check
143 `navigation.formAction === "/expected-path"` so unrelated navigations
144 don't trigger your local spinner. **Stop.**
145 - **Fail →** Step 5.
1465. **Need to render an optimistic value?**
147 - **Pass →** Read `navigation.formData?.get("field")` (page form) or
148 `fetcher.formData?.get("field")` (fetcher) — both are populated
149 while `state !== "idle"`. **Stop.**
150
151## Additional Documentation
152
153- **`<Form>` component**: See [references/form.md](references/form.md) for
154 `<Form>` vs native `<form>` vs `fetch()`, progressive enhancement,
155 redirect-after-success, and validation error display via `useActionData`.
156- **`useFetcher`**: See [references/fetcher.md](references/fetcher.md) for
157 inline mutations, list operations, popovers, `fetcher.state`,
158 `fetcher.data`, `fetcher.Form`, `fetcher.submit`, `fetcher.load`.
159- **Optimistic UI**: See
160 [references/optimistic-ui.md](references/optimistic-ui.md) for
161 `fetcher.formData` and `useNavigation.formData`, when to apply, and
162 reverting on failure.
163- **File uploads**: See [references/uploads.md](references/uploads.md)
164 for `unstable_parseMultipartFormData`,
165 `unstable_createMemoryUploadHandler`,
166 `unstable_createFileUploadHandler`, and bounded handlers.
167- **Intent-based actions**: See
168 [references/intent-actions.md](references/intent-actions.md) for
169 multiple actions on one route via the FormData `intent` field.
170
171## Comparison
172
173| Concern | `<Form>` | `useFetcher` | Native `<form>` | `fetch()` |
174|---|---|---|---|---|
175| URL change / history entry | Yes | No | Yes (hard nav) | No |
176| Works without JS | Yes | Yes | Yes | No |
177| Revalidates loaders | Yes | Yes | Yes (hard reload) | No |
178| Pending state hook | `useNavigation()` | `fetcher.state` | None | Manual |
179| Optimistic input source | `navigation.formData` | `fetcher.formData` | None | Manual |
180| In-app mutation use case | Create / delete / multi-step | Inline / row / toggle | External targets only | Never for own routes |