existential-birds/beagle / plugins/beagle-react/skills/remix-v2-forms
remix-v2-forms
VerifiedRemix 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.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 8.6 KB |
| references/fetcher.md | markdown | 6.8 KB |
| references/form.md | markdown | 8.3 KB |
| references/intent-actions.md | markdown | 4.2 KB |
| references/optimistic-ui.md | markdown | 6.1 KB |
| references/uploads.md | markdown | 5.4 KB |
references/intent-actions.md
View on GitHub# Multiple Actions on One Route (the `intent` Pattern)
A Remix route has exactly one `action` export. To handle multiple
operations (like, retweet, delete) without sprawling into separate route
files, encode the operation in a FormData field named `intent` and
switch on it inside the single action.
## The Pattern
```tsx
// app/routes/tweets.$id.tsx
import { json, type ActionFunctionArgs } from "@remix-run/node";
import { useFetcher } from "@remix-run/react";
export async function action({ request, params }: ActionFunctionArgs) {
const form = await request.formData();
const intent = form.get("intent");
switch (intent) {
case "like":
return json(await likeTweet(params.id!));
case "retweet":
return json(await retweetTweet(params.id!));
case "delete":
return json(await deleteTweet(params.id!));
default:
throw new Response("Unknown intent", { status: 400 });
}
}
export default function Tweet() {
const fetcher = useFetcher();
const pendingIntent = fetcher.formData?.get("intent");
return (
<fetcher.Form method="post">
<button name="intent" value="like" disabled={pendingIntent === "like"}>
Like
</button>
<button name="intent" value="retweet" disabled={pendingIntent === "retweet"}>
RT
</button>
<button name="intent" value="delete">
Delete
</button>
</fetcher.Form>
);
}
```
## Why It Works
Only the clicked submit button's `name=value` lands in the form body. So
when the user clicks "Like", `formData.get("intent")` is `"like"`; the
other two buttons contribute nothing. This is HTML-standard form behavior
and works without JS.
Per-button pending state comes from `fetcher.formData?.get("intent")` —
populated synchronously on submit, cleared at `idle`.
## When to Use It
- A row in a list has multiple related actions (like, retweet, delete).
- A form has a primary submit and a "Save as draft" variant.
- A modal handles a small group of related mutations.
When **not** to use it:
- Mutations operate on different resources (different URLs are clearer).
- Operations belong on a different route conceptually (e.g. user vs.
admin actions on the same record — split them).
- The intents have wildly different request shapes (validation gets
ugly fast).
## Pattern: Page Form Variant
The same pattern works with page-level `<Form>`:
```tsx
import { Form, useNavigation } from "@remix-run/react";
export default function PostForm() {
const nav = useNavigation();
const pending = nav.formData?.get("intent");
return (
<Form method="post">
<input name="body" />
<button name="intent" value="draft" disabled={pending === "draft"}>
Save Draft
</button>
<button name="intent" value="publish" disabled={pending === "publish"}>
Publish
</button>
</Form>
);
}
```
Filter on `nav.formAction` too if the route can be the target of multiple
unrelated forms.
## Anti-Patterns
- **Multiple `<form>` elements each posting to a different route** just
to disambiguate operations. Forces route file sprawl, duplicates
parsing, and breaks revalidation scope. Use one action with intents.
- **Reading `useActionData()` to detect which intent ran**, without
including the intent in the response. `useActionData` is per-route,
not per-intent — the component can't tell whether the "like" or the
"delete" returned. Either include the intent in the response
(`json({ intent: "like", ok: true })`) or use a separate
`useFetcher` per intent.
- **Defaulting to a "happy" intent in the action** when `intent` is
missing. Better to throw `400` so a bug in the UI doesn't silently
mutate the wrong way.
## Gotchas
- **Pressing Enter in a text input submits the first button in DOM
order.** Order your `<button>` elements so the safe / common operation
comes first. If you have a destructive action ("Delete"), put it
last and consider requiring a confirmation step.
- `formData.get("intent")` returns `FormDataEntryValue | null`. Compare
against string literals; do not pass it directly to a discriminated
union without narrowing.
- The `intent` field is just a convention — any name works as long as
the action and UI agree. `intent` is the conventional choice and
matches the broader Remix ecosystem.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |