Handle form submissions and data mutations with action exports and useActionData().
An action is a function exported from a page that handles data mutations, typically from a <Form> submission. React Router runs the action, returns the result, and makes it available to the page via useActionData().
| Export | Type | When it runs |
|---|---|---|
| action | function (async or sync) | On form submission or POST/PUT/DELETE |
| loader | function (async or sync) | Before the route renders (GET) |
| shouldRevalidate | function | Before a revalidation |
vite build, routes with an action are marked clientOnly and get a shell page instead of pre-rendered HTML.Export a function called action from your page. It receives the request context (including the submitted FormData). Return any serializable value.
Call useActionData() inside the page component to read the action's return value. It is undefined until the action runs for the first time.
| Hook | What it returns |
|---|---|
| useActionData() | The route's action return value, or undefined |
| useNavigation() | The current submission state (idle, submitting, loading) |
| useSubmit() | Programmatically submit a form |
A thrown error inside an action is caught by the nearest error.tsx boundary, the same way loader and render errors are.
Actions work with native HTML forms even when JavaScript is disabled (or before hydration finishes), as long as you use React Router's <Form> component instead of a plain <form>.
<form> tags do not trigger actions on client-side navigation. Use <Form> from react-router-dom for any form that submits to an action.Routes with an action are marked clientOnly, the same as routes with a loader. During vite build, the build tool writes a shell page for them because React Router does not run actions or loaders during static rendering.
| Route type | SSG output | What renders on first visit |
|---|---|---|
| No action | Full pre-rendered HTML | Instant paint from HTML |
| With action | Shell page (empty #root) | Client renders, then the form works |
Fetch data before a route renders.
Access loader data and navigation state.
Catch render errors and show a fallback UI.
Add backend endpoints with plain functions or a full Hono app.
Show a fallback while pages and layouts load.
How every route is pre-rendered to HTML at build time.
Handle form submissions and data mutations with action exports and useActionData().
An action is a function exported from a page that handles data mutations, typically from a <Form> submission. React Router runs the action, returns the result, and makes it available to the page via useActionData().
| Export | Type | When it runs |
|---|---|---|
| action | function (async or sync) | On form submission or POST/PUT/DELETE |
| loader | function (async or sync) | Before the route renders (GET) |
| shouldRevalidate | function | Before a revalidation |
vite build, routes with an action are marked clientOnly and get a shell page instead of pre-rendered HTML.Export a function called action from your page. It receives the request context (including the submitted FormData). Return any serializable value.
Call useActionData() inside the page component to read the action's return value. It is undefined until the action runs for the first time.
| Hook | What it returns |
|---|---|
| useActionData() | The route's action return value, or undefined |
| useNavigation() | The current submission state (idle, submitting, loading) |
| useSubmit() | Programmatically submit a form |
A thrown error inside an action is caught by the nearest error.tsx boundary, the same way loader and render errors are.
Actions work with native HTML forms even when JavaScript is disabled (or before hydration finishes), as long as you use React Router's <Form> component instead of a plain <form>.
<form> tags do not trigger actions on client-side navigation. Use <Form> from react-router-dom for any form that submits to an action.Routes with an action are marked clientOnly, the same as routes with a loader. During vite build, the build tool writes a shell page for them because React Router does not run actions or loaders during static rendering.
| Route type | SSG output | What renders on first visit |
|---|---|---|
| No action | Full pre-rendered HTML | Instant paint from HTML |
| With action | Shell page (empty #root) | Client renders, then the form works |
Fetch data before a route renders.
Access loader data and navigation state.
Catch render errors and show a fallback UI.
Add backend endpoints with plain functions or a full Hono app.
Show a fallback while pages and layouts load.
How every route is pre-rendered to HTML at build time.