This commit is contained in:
Tomas Dvorak
2026-02-24 10:33:59 +01:00
parent 409acd2e08
commit 898a3c303f
1374 changed files with 290409 additions and 29187 deletions
+17
View File
@@ -0,0 +1,17 @@
{
"id": "20477dc7cf5dfb536dbe5cb7",
"source": "solid:signals",
"type": "github-document",
"title": "use-action",
"content": "---\ntitle: useAction\nuse_cases: \u003e-\n programmatic forms, client-side mutations, imperative actions, non-form\n submissions\ntags:\n - actions\n - mutations\n - client\n - imperative\n - programmatic\nversion: '1.0'\ndescription: \u003e-\n Invoke actions programmatically without forms using useAction. Perfect for\n client-side mutations and imperative updates.\n---\n\nThe `useAction` primitive returns a function that triggers an [action](/solid-router/concepts/actions) when called.\n\n`useAction` requires client-side JavaScript and is not progressively enhanceable.\n\n## Import\n\n```tsx\nimport { useAction } from \"@solidjs/router\";\n```\n\n## Type\n\n```tsx\nfunction useAction\u003cT extends Array\u003cany\u003e, U, V\u003e(\n action: Action\u003cT, U, V\u003e\n): (...args: Parameters\u003cAction\u003cT, U, V\u003e\u003e) =\u003e Promise\u003cNarrowResponse\u003cU\u003e\u003e;\n```\n\n## Parameters\n\n### `action`\n\n- **Type:** `Action\u003cT, U, V\u003e`\n- **Required:** Yes\n\nThe action to be triggered.\n\n## Return value\n\n`useAction` returns a function that triggers the action.\nIt takes the same parameters as the action handler and returns a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves with the action's result.\n\n## Example\n\n```tsx\nimport { action, useAction } from \"@solidjs/router\";\n\nconst likePostAction = action(async (id: string) =\u003e {\n\t// ... Likes a post on the server.\n});\n\nfunction LikeButton(props: { postId: string }) {\n\tconst likePost = useAction(likePostAction);\n\n\treturn \u003cbutton onClick={() =\u003e likePost(props.postId)}\u003eLike\u003c/button\u003e;\n}\n```",
"url": "https://github.com/solidjs/solid-docs/blob/HEAD/src/routes/solid-router/reference/data-apis/use-action.mdx",
"metadata": {
"path": "src/routes/solid-router/reference/data-apis/use-action.mdx",
"repo": "solidjs/solid-docs",
"repo_url": "https://github.com/solidjs/solid-docs.git",
"size": 1525,
"source_type": "github"
},
"hash": "8d93e78514090934ac852dfb9dee065caa6f58af1bf981587b8cb4912bbc6ea8",
"timestamp": "2026-02-23T11:43:00.192789285+01:00"
}