Skip to content

Commit ceaa825

Browse files
amirhhashemikodiakhq[bot]LadyBluenotes
authored
Add info about error casting in in createResource (#1086)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Sarah <gerrardsarah@gmail.com>
1 parent 2cdf837 commit ceaa825

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/routes/reference/basic-reactivity/create-resource.mdx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@ You can call `mutate` to directly update the `data` signal (it works like any ot
2424
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)`.
2525

2626
`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.
3239

3340
`loading`, `error`, and `latest` are reactive getters and can be tracked.
3441

0 commit comments

Comments
 (0)