Skip to content

Add info about error casting in in createResource #1086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
eb1213e
Add info about error casting in createResource
amirhhashemi Feb 16, 2025
6498dff
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Feb 16, 2025
8e907af
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Feb 18, 2025
d1fb3fd
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Feb 18, 2025
7d8a1d5
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Feb 18, 2025
5bbb94b
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Feb 18, 2025
4da1b8e
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Feb 18, 2025
5d0fc4a
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Feb 18, 2025
cccc934
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Feb 18, 2025
ef3336a
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Feb 18, 2025
2741883
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Feb 25, 2025
a14fd6b
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Feb 25, 2025
13aa7f9
Update src/routes/reference/basic-reactivity/create-resource.mdx
amirhhashemi Feb 26, 2025
635c4b0
Update src/routes/reference/basic-reactivity/create-resource.mdx
amirhhashemi Feb 26, 2025
851712c
Update src/routes/reference/basic-reactivity/create-resource.mdx
amirhhashemi Feb 26, 2025
483321d
Update src/routes/reference/basic-reactivity/create-resource.mdx
amirhhashemi Feb 26, 2025
b679a66
Update src/routes/reference/basic-reactivity/create-resource.mdx
amirhhashemi Feb 26, 2025
7922bfe
remove the note
amirhhashemi Feb 26, 2025
88a221c
Merge branch 'main' into update-create-resource-error-type
LadyBluenotes Feb 26, 2025
052f3e8
Merge branch 'main' into update-create-resource-error-type
LadyBluenotes Feb 26, 2025
51a272e
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Feb 26, 2025
bbfe2cb
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Mar 4, 2025
094f4b5
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Mar 4, 2025
f45b95b
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Mar 6, 2025
693a7bc
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Mar 7, 2025
4c4a3df
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Mar 7, 2025
1bec6eb
Merge branch 'main' into update-create-resource-error-type
kodiakhq[bot] Mar 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/routes/reference/basic-reactivity/create-resource.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ You can call `mutate` to directly update the `data` signal (it works like any ot
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)`.

`data` works like a normal signal getter: use `data()` to read the last returned value of `fetchData`.
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.
(Note: if you anticipate errors, you may want to wrap `createResource` in an [ErrorBoundary](/reference/components/error-boundary).)

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()`.
This can be useful if you want to show the out-of-date data while the new data is loading.
But it also has extra reactive properties:

- `data.loading`: whether the fetcher has been called but not returned.
- `data.error`: if the request has errored out.
`createResource`: provides an `Error` object for `data.error`. It will show even if the fetcher throws something else.

- Fetcher throws an `Error` instance, `data.error` will be that instance.
- If the fetcher throws a string, `data.error.message` will contain that string.
- When the fetcher throws a value that is neither an `Error` nor a string, that value will be available as `data.error.cause`.

- 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()`.
This can be useful if you want to show the out-of-date data while the new data is loading.

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

Expand Down
Loading