Skip to main content

Actions

Actions handle data mutations like creating, updating, and deleting records. They run in response to form submissions and programmatic submissions.

Basic Action

Actions receive form data from POST, PUT, PATCH, or DELETE requests:
filename=app/routes/projects.new.tsx

Using Form

The Form component triggers actions when submitted:

Action Arguments

Actions receive the same arguments as loaders:

Form Data Formats

URL Encoded (default)

JSON

Multipart (file uploads)

Returning Data

Actions can return data to be used in the UI:

Using useActionData

Access action data with the useActionData hook:

Redirecting After Actions

Multiple Actions per Form

Use button values to differentiate actions:

Programmatic Submission

Submit forms programmatically with useSubmit:
Submit JSON data:
Track form submission state with useNavigation:

Error Handling

Validation

Client Actions

Use clientAction for client-only mutations: