Skip to content

Commit 505f86d

Browse files
Update createResource, add "state" field. (#918)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent dba7a15 commit 505f86d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ There are two ways to use `createResource`: you can pass the fetcher function as
88
The source signal will retrigger the fetcher whenever it changes, and its value will be passed to the fetcher.
99

1010
```tsx
11-
const [data, { mutate, refetch }] = createResource(fetchData)
11+
const [data, { mutate, refetch, state }] = createResource(fetchData)
1212
```
1313

1414
```tsx
15-
const [data, { mutate, refetch }] = createResource(source, fetchData)
15+
const [data, { mutate, refetch, state }] = createResource(source, fetchData)
1616
```
1717

1818
In these snippets, the fetcher is the function `fetchData`, and `data()` is undefined until `fetchData` finishes resolving.
@@ -49,7 +49,7 @@ async function fetchData(source, { value, refetching }) {
4949
// or equal to the optional data passed: `refetch(info)`
5050
}
5151

52-
const [data, { mutate, refetch }] = createResource(getQuery, fetchData)
52+
const [data, { mutate, refetch, state }] = createResource(getQuery, fetchData)
5353

5454
// read value
5555
data()
@@ -102,7 +102,7 @@ You can use the new `ssrLoadFrom` option for this.
102102
Instead of using the default `server` value, you can pass `initial` and the resource will use `initialValue` as if it were the result of the first fetch for both SSR and hydration.
103103

104104
```tsx
105-
const [data, { mutate, refetch }] = createResource(() => params.id, fetchUser, {
105+
const [data, { mutate, refetch, state }] = createResource(() => params.id, fetchUser, {
106106
initialValue: preloadedData,
107107
ssrLoadFrom: "initial",
108108
})
@@ -197,4 +197,4 @@ function createResource<T, U>(
197197
options?: ResourceOptions<T, U>
198198
): ResourceReturn<T>
199199

200-
```
200+
```

0 commit comments

Comments
 (0)