Skip to content

Commit 5cdbdab

Browse files
committed
Add docs to route.action
1 parent 99c9a0e commit 5cdbdab

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/route/action.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ formData.get("lyrics");
101101

102102
For more information on `formData` see [Working with FormData][workingwithformdata].
103103

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+
104120
## Returning Responses
105121

106122
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
144160
[form]: ../components/form
145161
[workingwithformdata]: ../guides/form-data
146162
[useactiondata]: ../hooks/use-action-data
163+
[usesubmit]: ../hooks/use-submit
147164
[returningresponses]: ./loader#returning-responses
148165
[createbrowserrouter]: ../routers/create-browser-router

0 commit comments

Comments
 (0)