liveBook · Manning

Remix action

As explained in React in Depth

A Remix action is a server-side function associated with a route that handles non-GET mutations submitted to that route.

A Remix action is a server-side function attached to a route that handles submitted form data and other mutations. It complements loader(), which reads route data; action() receives the request and can update application state, cookies, or models. section 11.3.3 section 12.3.4

Use route actions to:

  • Read submitted values with request.formData(). section 11.3.3
  • Persist local preferences through server-side cookies, including temperature and time-format settings. section 11.3.3
  • Update domain data, such as user income, or create expenses with existing or new categories. section 12.3.4
  • Support progressive enhancement: browser forms still work without JavaScript, while Remix can submit the form without a full page reload when JavaScript is enabled. section 11.3.3

City preference route

A city route combines a loader for city data and default formats with an action for submitted preference changes. The action reads form data, delegates cookie updates to helpers, serializes the new cookie, and redirects back with a Set-Cookie header. The same form remains functional when JavaScript is unavailable. section 11.3.3

Figure 11.18 The overall structure of the Remix city route contains three parts. Besides the data package and component, which I’ve covered extensively, we also have a data handler that’s capable of handling form submissions.
figure

Use the route-structure diagram to inspect how the action sits beside the component and loader/data package as the form-submission handler. section 11.3.3

How React in Depth covers it

How deep it goes
Explains request form-data handling, cookie serialization, redirects, and model connections through implementation examples.
Examples
Uses city-format cookie toggles and expense-tracker income and expense mutations as concrete route examples.
What it assumes
Assumes familiarity with Remix routes and loaders while demonstrating form requests, cookies, redirects, and model updates.
What you can do after
Apply it via Remix to build progressively enhanced routes that read submissions and persist server-side mutations.
How it connects
Connects actions with loaders, forms, cookies, redirects, routes, and server-side data models.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React in Depth. The section links point to the parts of the book it draws on.