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.
Revalidate cached functions
Revalidate all (default)
By default all cached functions will be revalidated wether the action does not return or return a "normal" response.
Revalidate specific cached keys
By returning a response with solid-router's json
, reload
or redirect
helpers you can pass a key / keys to the revalidate prop as the second argument of the json response helper.
You can either pass as string
directly or use the cached functions key
or keyFor
props.
Prevent revalidation
To opt out of any revalidation you can pass any string
to revalidate which is not a key of any cached function.
Revalidate without action
Cached functions can also be revalidated by the revalidate
helper.
This is also great if you want to set your own "refresh" interval e.g. poll data every 30 seconds.