Skip to content

Commit 802cd48

Browse files
committed
Add useAction reference
1 parent 121f9b6 commit 802cd48

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

src/routes/solid-router/reference/data-apis/action.mdx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,6 @@ The solution is to provide a unique name.
6868
const myAction = action(async (args) => {}, "my-action");
6969
```
7070

71-
## `useAction`
72-
73-
Instead of forms, actions can directly be wrapped in a `useAction` primitive.
74-
This is how router context is created.
75-
76-
```jsx
77-
// in component
78-
const submit = useAction(myAction);
79-
submit(...args);
80-
81-
```
82-
83-
The outside of a form context can use custom data instead of `formData`.
84-
These helpers preserve types.
85-
86-
However, even when used with server functions, such as with [SolidStart](https://start.solidjs.com/getting-started/what-is-solidstart), this requires client-side JavaScript and is not progressively enhanceable like forms are.
87-
8871
## `useSubmission`/`useSubmissions`
8972

9073
These functions are used when incorporating optimistic updates during ongoing actions.

src/routes/solid-router/reference/data-apis/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"create-async.mdx",
77
"create-async-store.mdx",
88
"query.mdx",
9+
"use-action.mdx",
910
"use-submission.mdx",
1011
"use-submissions.mdx"
1112
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: useAction
3+
---
4+
5+
`useAction` allows you to programmatically invoke an [`action`](/solid-router/reference/data-apis/action).
6+
7+
```tsx
8+
import { useAction } from "@solidjs/router";
9+
import { updateNameAction } from "./actions";
10+
11+
const updateName = useAction(updateNameAction);
12+
13+
const result = updateName("John Wick");
14+
```
15+
16+
<Callout type="info" title="Note">
17+
`useAction` requires client-side JavaScript and is not progressively
18+
enhanceable.
19+
</Callout>
20+
21+
## Parameters
22+
23+
- `action`: the action you want to invoke.
24+
25+
## Returns
26+
27+
`useAction` returns a function that lets you invoke the action. It has the same signature as the action itself.

0 commit comments

Comments
 (0)