You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -7,7 +7,6 @@ They are designed to simplify your application's data flow, ensure a consistent
7
7
8
8
Actions provide several key benefits:
9
9
10
-
-**Centralized Logic**: Encapsulate the logic for data modifications in a single, reusable function.
11
10
-**Integrated State Management**: Solid Router automatically tracks the execution state of an action (whether it's pending, successful, or has encountered an error), making it easy to build reactive UI feedback.
12
11
-**Automatic Data Revalidation**: By default, after an action successfully completes, Solid Router revalidates any queries on the same page.
13
12
This ensures your UI reflects the latest data without manual intervention.
Here, `updatePostAction` receives `postId` (passed via `with`), and then the `formData` from the form.
171
+
172
+
### Invoking Actions Programmatically with `useAction`
173
+
174
+
While forms are highly recommended for progressive enhancement, there are scenarios where you might need to trigger an action directly from a Solid component, outside of a `<form>` element.
175
+
The `useAction` primitive allows you to do this.
176
+
177
+
`useAction` takes an action as an argument and returns a function that, when called, will invoke the action with the provided parameters.
While automatic revalidation is convenient, there are times you need more control.
241
+
Solid Router's response helpers allow you to precisely manage which queries are revalidated, or even disable revalidation entirely for a specific action.
242
+
You'll learn more about these helpers in the next section.
243
+
244
+
## Response helpers
245
+
246
+
Solid Router provides special response helpers that enable your actions to explicitly dictate routing and query revalidation:
247
+
248
+
-[`json`](/solid-router/reference/response-helpers/json): Allows customizing query revalidation behavior when the action returns something.
249
+
While it's not necessary to use this helper to return a value from an action (a plain JavaScript value also works), the `json` helper can be used when you want to return data **and** customize query revalidation.
250
+
-[`redirect`](/solid-router/reference/response-helpers/redirect): Performs a redirect.
In this example, the form's submit button is disabled during `submission.pending`, and appropriate messages are shown based on `submission.error` or `submission.result`.
341
+
The `clear` method resets the submission state, and `retry` re-executes the last submission with its original input.
342
+
343
+
For more details, see the [`useSubmission` API reference](/solid-router/reference/data-apis/use-submission).
344
+
345
+
:::tip
346
+
If you need to track multiple concurrent or recent submissions for an action (e.g., a list of file uploads, a queue of items being processed), the [`useSubmissions` primitive](/solid-router/reference/data-apis/use-submissions) can be used.
0 commit comments