Skip to content

Commit ad5892c

Browse files
committed
iteration 1
1 parent b04a853 commit ad5892c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/routes/solid-start/guides/actions-and-mutations.mdx

+9-9
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,32 @@ export default function Page() {
3535

3636
When invoked in a form, the action automatically receives the [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData/FormData) object. You can extract the field data using the native `FormData` methods.
3737

38-
If your action accepts typed data, you can use the `with` method to pass custom data to the action:
38+
### Passing additional arguments
39+
40+
When you need to pass additional arguments to your action, you can use the `with` method:
3941

4042
```tsx {14} title="src/routes/index.tsx"
41-
import { createSignal } from "solid-js";
4243
import { action } from "@solidjs/router";
4344

44-
const addPost = action(async (title: string) => {
45+
const addPost = action(async (userId: number, formData: FormData) => {
46+
const title = formData.get("title");
4547
await fetch("https://my-api.com/posts", {
4648
method: "POST",
47-
body: JSON.stringify({ title }),
49+
body: JSON.stringify({ userId, title }),
4850
});
4951
}, "addPost");
5052

5153
export default function Page() {
52-
const [title, setTitle] = createSignal("");
54+
const userId = 1;
5355
return (
54-
<form action={addPost.with(title())} method="post">
55-
<input value={title()} onChange={(e) => setTitle(e.target.value)} />
56+
<form action={addPost.with(userId)} method="post">
57+
<input name="title" />
5658
<button>Add Post</button>
5759
</form>
5860
);
5961
}
6062
```
6163

62-
Note that the action takes a `string` as its first parameter rather than a `FormData`.
63-
6464
## Showing pending UI
6565

6666
To display a pending UI while the action is being executed, you can use the [`useSubmission`](/solid-router/reference/data-apis/use-submission) primitive:

0 commit comments

Comments
 (0)