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
Copy file name to clipboardExpand all lines: docs/route/action.md
+17Lines changed: 17 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -101,6 +101,22 @@ formData.get("lyrics");
101
101
102
102
For more information on `formData` see [Working with FormData][workingwithformdata].
103
103
104
+
### Opt-in serialization types
105
+
106
+
Note that when using [`useSubmit`][usesubmit] you may also pass `encType: "application/json"` or `encType: "text/plain"` to instead serialize your payload into `request.json()` or `request.text()`.
107
+
108
+
## `payload`
109
+
110
+
A `payload` is provided to your action when you submit imperatively with [`useSubmit`][usesubmit] and provide a raw javascript value. This value might also be serialized into the request depending on the `encType`.
111
+
112
+
```jsx
113
+
function Component {
114
+
let submit = useSubmit();
115
+
submit({ key:"value" }, { encType:null });
116
+
// action payload is { key: 'value' }
117
+
}
118
+
```
119
+
104
120
## Returning Responses
105
121
106
122
While you can return anything you want from an action and get access to it from [`useActionData`][useactiondata], you can also return a web [Response][response].
@@ -144,5 +160,6 @@ For more details and expanded use cases, read the [errorElement][errorelement] d
0 commit comments