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: src/routes/reference/basic-reactivity/create-resource.mdx
+12-5Lines changed: 12 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,11 +24,18 @@ You can call `mutate` to directly update the `data` signal (it works like any ot
24
24
You can also call refetch to rerun the fetcher directly, and pass an optional argument to provide additional info to the fetcher e.g `refetch(info)`.
25
25
26
26
`data` works like a normal signal getter: use `data()` to read the last returned value of `fetchData`.
27
-
But it also has extra reactive properties: `data.loading` tells you if the fetcher has been called but not returned, and `data.error` tells you if the request has errored out; if so, it contains the error thrown by the fetcher.
28
-
(Note: if you anticipate errors, you may want to wrap `createResource` in an [ErrorBoundary](/reference/components/error-boundary).)
29
-
30
-
As of **v1.4.0**, `data.latest` will return the last returned value and won't trigger [Suspense](/reference/components/suspense) and [transitions](#TODO); if no value has been returned yet, `data.latest` acts the same as `data()`.
31
-
This can be useful if you want to show the out-of-date data while the new data is loading.
27
+
But it also has extra reactive properties:
28
+
29
+
-`data.loading`: whether the fetcher has been called but not returned.
30
+
-`data.error`: if the request has errored out.
31
+
`createResource`: provides an `Error` object for `data.error`. It will show even if the fetcher throws something else.
32
+
33
+
- Fetcher throws an `Error` instance, `data.error` will be that instance.
34
+
- If the fetcher throws a string, `data.error.message` will contain that string.
35
+
- When the fetcher throws a value that is neither an `Error` nor a string, that value will be available as `data.error.cause`.
36
+
37
+
- As of **v1.4.0**, `data.latest` returns the last value received and will not trigger [Suspense](/reference/components/suspense) or [transitions](#TODO); if no value has been returned yet, `data.latest` will act the same as `data()`.
38
+
This can be useful if you want to show the out-of-date data while the new data is loading.
32
39
33
40
`loading`, `error`, and `latest` are reactive getters and can be tracked.
0 commit comments