Performance: Form component and method
This affects page load speed and interaction responsiveness by controlling how form submissions are handled and how much JavaScript is needed.
import { Form } from '@remix-run/react'; export default function GoodForm() { return ( <Form method="post"> <input name="email" type="email" required aria-label="Email address" /> <button type="submit">Send</button> </Form> ); }
import React from 'react'; export default function BadForm() { return ( <form action="/submit" method="post"> <input name="email" type="email" required /> <button type="submit">Send</button> </form> ); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Plain HTML form with full reload | Minimal DOM nodes | Triggers 1 full reflow and repaint on submit | High paint cost due to full reload | [X] Bad |
| Remix Form component with method | Minimal DOM nodes | No reflow from submit, only targeted updates | Low paint cost, no full reload | [OK] Good |
method attribute in Remix's Form component specify?method attributemethod attribute defines how the browser sends form data to the server, typically using GET or POST.Form componentForm component uses this attribute to decide whether to send data via URL parameters (GET) or request body (POST).Form component?method attribute in lowercase, so "post" is correct, while "POST" or "Post" may cause issues.method="post". Using "get" sends data in the URL, which is not POST.actionData after submitting the form?import { Form, useActionData } from "@remix-run/react";
export function action({ request }) {
return request.formData().then(data => {
return { name: data.get("name") };
});
}
export default function MyForm() {
const actionData = useActionData();
return (
Send
{actionData ? Hello, {actionData.name}!
: null}
);
}import { Form } from "@remix-run/react";
export default function MyForm() {
return (
Submit
);
}
export function action({ request }) {
const formData = request.formData();
const email = formData.get("email");
return { email };
}useSearchParams().useSearchParams() allows reading query params reactively, so the page updates without full reload.useActionData() expect POST method and server action data, not query params. Mixing methods and hooks incorrectly won't work.Pass the test and this pattern moves unknown