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
Add support for manual fetcher key specification via `useFetcher({ key: string })` so you can access the same fetcher instance from different components in your application without prop-drilling ([RFC](https://github.com/remix-run/remix/discussions/7698))
6
+
7
+
- Fetcher keys are now also exposed on the fetchers returned from `useFetchers` so that they can be looked up by `key`
Add `navigate`/`fetcherKey` params/props to `useSumbit`/`Form` to support kicking off a fetcher submission under the hood with an optionally user-specified `key`
6
+
7
+
- Invoking a fetcher in this way is ephemeral and stateless
8
+
- If you need to access the state of one of these fetchers, you will need to leverage `useFetcher({ key })` to look it up elsewhere
Copy file name to clipboardExpand all lines: docs/components/form.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -197,6 +197,14 @@ function Project() {
197
197
198
198
As you can see, both forms submit to the same route but you can use the `request.method` to branch on what you intend to do. After the actions completes, the `loader` will be revalidated and the UI will automatically synchronize with the new data.
199
199
200
+
## `navigate`
201
+
202
+
You can tell the form to skip the navigation and use a [fetcher][usefetcher] internally by specifying `<Form navigate={false}>`. This is essentially a shorthand for `useFetcher()` + `<fetcher.Form>` where you don't care about the resulting data and only want to kick off a submission and access the pending state via [`useFetchers()`][usefetchers].
203
+
204
+
## `fetcherKey`
205
+
206
+
When using a non-navigating `Form`, you may also optionally specify your own fetcher key to use via `<Form navigate={false} fetcherKey="my-key">`.
207
+
200
208
## `replace`
201
209
202
210
Instructs the form to replace the current entry in the history stack, instead of pushing the new entry.
@@ -367,6 +375,7 @@ You can access those values from the `request.url`
Copy file name to clipboardExpand all lines: docs/hooks/use-fetcher.md
+46-12Lines changed: 46 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,15 +60,37 @@ Fetchers have a lot of built-in behavior:
60
60
- Handles uncaught errors by rendering the nearest `errorElement` (just like a normal navigation from `<Link>` or `<Form>`)
61
61
- Will redirect the app if your action/loader being called returns a redirect (just like a normal navigation from `<Link>` or `<Form>`)
62
62
63
-
## `fetcher.state`
63
+
## Options
64
64
65
-
You can know the state of the fetcher with `fetcher.state`. It will be one of:
65
+
### `key`
66
66
67
-
-**idle** - nothing is being fetched.
68
-
-**submitting** - A route action is being called due to a fetcher submission using POST, PUT, PATCH, or DELETE
69
-
-**loading** - The fetcher is calling a loader (from a `fetcher.load`) or is being revalidated after a separate submission or `useRevalidator` call
67
+
By default, `useFetcher` generate a unique fetcher scoped to that component (however, it may be looked up in [`useFetchers()`][use_fetchers] while in-flight). If you want to identify a fetcher with your own key such that you can access it from elsewhere in your app, you can do that with the `key` option:
Copy file name to clipboardExpand all lines: docs/hooks/use-submit.md
+9-1Lines changed: 9 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -150,7 +150,15 @@ submit(null, {
150
150
<Formaction="/logout"method="post" />;
151
151
```
152
152
153
-
Because submissions are navigations, the options may also contain the other navigation related props from [`<Form>`][form] such as `replace`, `state`, `preventScrollReset`, `relative`, `unstable_viewTransition` etc.
153
+
Because submissions are navigations, the options may also contain the other navigation related props from [`<Form>`][form] such as:
0 commit comments