Skip to content

Commit d4ec21b

Browse files
committed
changelog/docs updates
1 parent 9debb5c commit d4ec21b

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

.changeset/raw-payload-submission.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Add support for `application/json` and `text/plain` encodings for `useSubmit`/`f
99
function Component() {
1010
let navigation = useNavigation();
1111
let submit = useSubmit();
12-
submit({ key: "value" });
12+
submit({ key: "value" }, { method: "post" });
1313
// navigation.formEncType => "application/x-www-form-urlencoded"
1414
// navigation.formData => FormData instance
1515
}
@@ -25,7 +25,7 @@ async function action({ request }) {
2525
function Component() {
2626
let navigation = useNavigation();
2727
let submit = useSubmit();
28-
submit({ key: "value" }, { encType: "application/json" });
28+
submit({ key: "value" }, { method: "post", encType: "application/json" });
2929
// navigation.formEncType => "application/json"
3030
// navigation.json => { key: "value" }
3131
}
@@ -41,7 +41,7 @@ async function action({ request }) {
4141
function Component() {
4242
let navigation = useNavigation();
4343
let submit = useSubmit();
44-
submit("Text submission", { encType: "text/plain" });
44+
submit("Text submission", { method: "post", encType: "text/plain" });
4545
// navigation.formEncType => "text/plain"
4646
// navigation.text => "Text submission"
4747
}

docs/hooks/use-submit.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,28 +96,38 @@ submit([
9696
]);
9797
```
9898

99-
The default behavior if you submit a JSON object is to encode the data into `FormData`:
99+
The default behavior if you submit a JSON object for a POST submission is to encode the data into `FormData`:
100100

101101
```tsx
102-
submit({ key: "value" });
102+
submit({ key: "value" }, { method: "post" });
103103
// will serialize into request.formData() in your action
104+
// and will show up on useNavigation().formData during the navigation
104105
```
105106

106107
Or you can opt-into JSON encoding:
107108

108109
```tsx
109-
submit({ key: "value" }, { encType: "application/json" });
110+
submit(
111+
{ key: "value" },
112+
{ method: "post", encType: "application/json" }
113+
);
110114
// will serialize into request.json() in your action
115+
// and will show up on useNavigation().json during the navigation
111116

112-
submit('{"key":"value"}', { encType: "application/json" });
117+
submit('{"key":"value"}', {
118+
method: "post",
119+
encType: "application/json",
120+
});
113121
// will encode into request.json() in your action
122+
// and will show up on useNavigation().json during the navigation
114123
```
115124

116125
Or plain text:
117126

118127
```tsx
119-
submit("value", { encType: "text/plain" });
128+
submit("value", { method: "post", encType: "text/plain" });
120129
// will serialize into request.text() in your action
130+
// and will show up on useNavigation().text during the navigation
121131
```
122132

123133
## Submit options
@@ -126,8 +136,8 @@ The second argument is a set of options that map (mostly) directly to form submi
126136

127137
```tsx
128138
submit(null, {
129-
action: "/logout",
130139
method: "post",
140+
action: "/logout",
131141
});
132142

133143
// same as

0 commit comments

Comments
 (0)