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/hooks/use-fetcher.md
+8-3Lines changed: 8 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ new: true
5
5
6
6
# `useFetcher`
7
7
8
-
In HTML/HTTP, data mutations and loads are modeled with navigation: `<a href>` and `<form action>`. Both cause a navigation in the browser. The React Router equivalents are `<Link>` and `<Form>`.
8
+
In HTML/HTTP, data mutations and loads are modeled with navigation: `<a href>` and `<form action>`. Both cause a navigation in the browser. The React Router equivalents are [`<Link>`][link] and [`<Form>`][form].
9
9
10
10
But sometimes you want to call a loader outside of navigation, or call an action (and get the data on the page to revalidate) without changing the URL. Or you need to have multiple mutations in-flight at the same time.
11
11
@@ -61,8 +61,8 @@ Fetchers have a lot of built-in behavior:
61
61
You can know the state of the fetcher with `fetcher.state`. It will be one of:
62
62
63
63
-**idle** - nothing is being fetched.
64
-
-**submitting** - A form has been submitted. If the method is GET, then the route loader is being called. If POST, PUT, PATCH, or DELETE, then the route action is being called.
65
-
-**loading** - The data on the page is being revalidated after an action submission
64
+
-**submitting** - A route action is being called due to a fetcher submission using POST, PUT, PATCH, or DELETE
65
+
-**loading** - The fetcher is calling a loader (from a `fetcher.load`) or the route data on the page is being revalidated after a fetcher submission
66
66
67
67
## `fetcher.Form`
68
68
@@ -103,6 +103,8 @@ Although a URL might match multiple nested routes, a `fetcher.load()` call will
103
103
104
104
If you find yourself calling this function inside of click handlers, you can probably simplify your code by using `<fetcher.Form>` instead.
105
105
106
+
<docs-info>Any `fetcher.load` calls that are active on the page will be re-executed as part of revalidation (either after a navigation submission, another fetcher submission, or a `useRevalidator()` call)</docs-info>
107
+
106
108
## `fetcher.submit()`
107
109
108
110
The imperative version of `<fetcher.Form>`. If a user interaction should initiate the fetch, you should use `<fetcher.Form>`. But if you, the programmer are initiating the fetch (not in response to a user clicking a button, etc.), then use this function.
@@ -217,3 +219,6 @@ Tells you the method of the form being submitted: get, post, put, patch, or dele
0 commit comments