action
Edit this pageActions are data mutations that can trigger invalidations and further routing. A list of prebuilt response helpers can be found below.
Actions only work with post requests.
This means forms require method="post"
.
A with
method can be used when typed data is required.
This removes the need to use FormData
or other additional hidden fields.
The with
method works similar to bind
, which applies the arguments in order.
Without with
:
Using with
:
Notes of <form>
implementation and SSR
This requires stable references because a string can only be serialized as an attribute, and it is crucial for consistency across SSR. where these references must align. The solution is to provide a unique name.
useAction
Instead of forms, actions can directly be wrapped in a useAction
primitive.
This is how router context is created.
The outside of a form context can use custom data instead of formData
.
These helpers preserve types.
However, even when used with server functions, such as with SolidStart, this requires client-side JavaScript and is not progressively enhanceable like forms are.
useSubmission
/useSubmissions
These functions are used when incorporating optimistic updates during ongoing actions. They provide either a singular Submission (the latest one), or a collection of Submissions that match, with an optional filtering function.