Skip to content

Commit 26471d4

Browse files
thecode00timdorr
andauthored
Add usenavigation formAction, formMethod, formEncType doc (#11051)
Co-authored-by: Tim Dorr <[email protected]>
1 parent 5f152fc commit 26471d4

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

contributors.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
- stmtk1
214214
- swalker326
215215
- tanayv
216+
- thecode00
216217
- theostavrides
217218
- thisiskartik
218219
- thomasverleye

docs/hooks/use-navigation.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function SomeComponent() {
2727
navigation.text;
2828
navigation.formAction;
2929
navigation.formMethod;
30+
navigation.formEncType;
3031
}
3132
```
3233

@@ -108,6 +109,45 @@ This tells you what the next [location][location] is going to be.
108109

109110
Note that this link will not appear "pending" if a form is being submitted to the URL the link points to, because we only do this for "loading" states. The form will contain the pending UI for when the state is "submitting", once the action is complete, then the link will go pending.
110111

112+
## `navigation.formAction`
113+
114+
Any POST, PUT, PATCH, or DELETE navigation that started from a `<Form>` or `useSubmit` will have form's submission action route's path value available in `navigation.formAction`.
115+
116+
In the case of a GET form submission, `navigation.formAction` will be empty
117+
118+
If you submitted the form at `example.com/id`, then `navigation.formAction` would be "/id"
119+
120+
## `navigation.formMethod`
121+
122+
Any POST, PUT, PATCH, or DELETE navigation that started from a `<Form>` or `useSubmit` will have form's submission method value available in `navigation.formMethod`.
123+
124+
In the case of a GET form submission, `navigation.formMethod` will be empty
125+
126+
Here is an example. Please note that `navigation.formMethod` is in lowercase
127+
128+
```tsx
129+
function SubmitButton() {
130+
const navigation = useNavigation();
131+
if (navigation.formMethod){
132+
console.log(navigation.formMethod) // post
133+
}
134+
135+
return (
136+
<Form method="POST">
137+
<button>Submit</button>
138+
</Form>
139+
);
140+
}
141+
```
142+
143+
## `navigation.formEncType`
144+
145+
Any POST, PUT, PATCH, or DELETE navigation that started from a `<Form>` or `useSubmit` will have form's submission method value available in `navigation.formEncType`.
146+
147+
This property can be one of the four values: "text/plain," "application/json," "multipart/form-data," or "application/x-www-form-urlencoded."
148+
149+
In the case of a GET form submission, `navigation.formEncType` will be empty
150+
111151
[location]: ../utils/location
112152
[pickingarouter]: ../routers/picking-a-router
113153
[api-development-strategy]: ../guides/api-development-strategy

0 commit comments

Comments
 (0)