Skip to content

Commit f47da59

Browse files
committed
docs(guides): fix docs
1 parent 864cd6e commit f47da59

File tree

7 files changed

+63
-23
lines changed

7 files changed

+63
-23
lines changed

docs/src/pages/guides/initial-query-data.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: Initial Query Data
66
There are many ways to supply initial data for a query to the cache before you need it:
77

88
- Declaratively:
9-
- Provide `initialData` to a query to prepopulate the its cache if empty
9+
- Provide `initialData` to a query to prepopulate its cache if empty
1010
- Imperatively:
1111
- [Prefetch the data using `queryClient.prefetchQuery`](../prefetching)
1212
- [Manually place the data into the cache using `queryClient.setQueryData`](../prefetching)
@@ -42,7 +42,7 @@ By default, `initialData` is treated as totally fresh, as if it were just fetche
4242

4343
```js
4444
function Todos() {
45-
// Show initialTodos immeidately, but won't refetch until another interaction event is encountered after 1000 ms
45+
// Show initialTodos immediately, but won't refetch until another interaction event is encountered after 1000 ms
4646
return useQuery('todos', () => fetch('/todos'), {
4747
initialData: initialTodos,
4848
staleTime: 1000,
@@ -53,7 +53,7 @@ By default, `initialData` is treated as totally fresh, as if it were just fetche
5353
- So what if your `initialData` isn't totally fresh? That leaves us with the last configuration that is actually the most accurate and uses an option called `initialDataUpdatedAt`. This options allows you to pass a numeric JS timestamp in milliseconds of when the initialData itself was last updated, e.g. what `Date.now()` provides. Take note that if you have a unix timestamp, you'll need to convert it to a JS timestamp by multiplying it by `1000`.
5454
```js
5555
function Todos() {
56-
// Show initialTodos immeidately, but won't refetch until another interaction event is encountered after 1000 ms
56+
// Show initialTodos immediately, but won't refetch until another interaction event is encountered after 1000 ms
5757
return useQuery('todos', () => fetch('/todos'), {
5858
initialData: initialTodos,
5959
staleTime: 60 * 1000 // 1 minute

docs/src/pages/guides/mutations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Mutations
55

66
Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects. For this purpose, Svelte Query exports a `useMutation` hook.
77

8-
Here's an example of a mutation that adds a new todo the server:
8+
Here's an example of a mutation that adds a new todo to the server:
99

1010
```markdown
1111
<script>
@@ -214,7 +214,7 @@ const queryClient = new QueryClient()
214214
// Define the "addTodo" mutation
215215
queryClient.setMutationDefaults('addTodo', {
216216
mutationFn: addTodo,
217-
onMutate: variables => {
217+
onMutate: async (variables) => {
218218
// Cancel current queries for the todos list
219219
await queryClient.cancelQueries('todos')
220220

docs/src/pages/guides/placeholder-query-data.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Placeholder data allows a query to behave as if it already has data, similar to
1212
There are a few ways to supply placeholder data for a query to the cache before you need it:
1313

1414
- Declaratively:
15-
- Provide `placeholderData` to a query to prepopulate the its cache if empty
15+
- Provide `placeholderData` to a query to prepopulate its cache if empty
1616
- Imperatively:
1717
- [Prefetch or fetch the data using `queryClient` and the `placeholderData` option](../prefetching)
1818

docs/src/pages/guides/query-invalidation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ queryClient.invalidateQueries('todos')
1717
When a query is invalidated with `invalidateQueries`, two things happen:
1818

1919
- It is marked as stale. This stale state overrides any `staleTime` configurations being used in `useQuery` or related hooks
20-
- If the query is currently being rendered via `useQuery` or related hooks), it will also be refetched in the background
20+
- If the query is currently being rendered via `useQuery` or related hooks, it will also be refetched in the background
2121

2222
## Query Matching with `invalidateQueries`
2323

docs/src/pages/reference/QueryClient.md

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ await queryClient.prefetchQuery('posts', fetchPosts)
2323

2424
Its available methods are:
2525

26-
- [`fetchQuery`](#queryclientfetchquerydata)
26+
- [`fetchQuery`](#queryclientfetchquery)
27+
- [`fetchInfiniteQuery`](#queryclientfetchinfinitequery)
2728
- [`prefetchQuery`](#queryclientprefetchquery)
29+
- [`prefetchInfiniteQuery`](#queryclientprefetchinfinitequery)
2830
- [`getQueryData`](#queryclientgetquerydata)
2931
- [`setQueryData`](#queryclientsetquerydata)
3032
- [`getQueryState`](#queryclientgetquerystate)
@@ -86,12 +88,33 @@ try {
8688

8789
**Options**
8890

89-
The options for `fetchQuery` are exactly the same as those of [`useQuery`](#usequery).
91+
The options for `fetchQuery` are exactly the same as those of [`useQuery`](./useQuery), except the following: `enabled, refetchInterval, refetchIntervalInBackground, refetchOnWindowFocus, refetchOnReconnect, notifyOnChangeProps, notifyOnChangePropsExclusions, onSuccess, onError, onSettled, useErrorBoundary, select, suspense, keepPreviousData, placeholderData`; which are stictly for useQuery and useInfiniteQuery. You can check the [source code](https://github.com/TanStack/svelte-query/blob/864cd6e31b19cea5483d1809d6e3afc1499b48d6/src/queryCore/core/types.ts#L83) for more clarity.
9092

9193
**Returns**
9294

9395
- `Promise<TData>`
9496

97+
## `queryClient.fetchInfiniteQuery`
98+
99+
`fetchInfiniteQuery` is similar to `fetchQuery` but can be used to fetch and cache an infinite query.
100+
101+
```js
102+
try {
103+
const data = await queryClient.fetchInfiniteQuery(queryKey, queryFn)
104+
console.log(data.pages)
105+
} catch (error) {
106+
console.log(error)
107+
}
108+
```
109+
110+
**Options**
111+
112+
The options for `fetchInfiniteQuery` are exactly the same as those of [`fetchQuery`](#queryclientfetchquery).
113+
114+
**Returns**
115+
116+
- `Promise<InfiniteData<TData>>`
117+
95118
## `queryClient.prefetchQuery`
96119

97120
`prefetchQuery` is an asynchronous method that can be used to prefetch a query before it is needed or rendered with `useQuery` and friends. The method works the same as `fetchQuery` except that is will not throw or return any data.
@@ -108,7 +131,24 @@ await queryClient.prefetchQuery(queryKey)
108131

109132
**Options**
110133

111-
The options for `prefetchQuery` are exactly the same as those of [`useQuery`](#usequery).
134+
The options for `prefetchQuery` are exactly the same as those of [`fetchQuery`](#queryclientfetchquery).
135+
136+
**Returns**
137+
138+
- `Promise<void>`
139+
- A promise is returned that will either immediately resolve if no fetch is needed or after the query has been executed. It will not return any data or throw any errors.
140+
141+
## `queryClient.prefetchInfiniteQuery`
142+
143+
`prefetchInfiniteQuery` is similar to `prefetchQuery` but can be used to prefetch and cache an infinite query.
144+
145+
```js
146+
await queryClient.prefetchInfiniteQuery(queryKey, queryFn)
147+
```
148+
149+
**Options**
150+
151+
The options for `prefetchInfiniteQuery` are exactly the same as those of [`fetchQuery`](#queryclientfetchquery).
112152

113153
**Returns**
114154

@@ -270,13 +310,10 @@ queryClient.removeQueries(queryKey, { exact: true })
270310

271311
- `queryKey?: QueryKey`: [Query Keys](../guides/query-keys)
272312
- `filters?: QueryFilters`: [Query Filters](../guides/query-filters)
273-
- `resetOptions?: ResetOptions`:
274-
- `throwOnError?: boolean`
275-
- When set to `true`, this method will throw if any of the query refetch tasks fail.
276313

277314
**Returns**
278315

279-
This method returns a promise that resolves when all active queries have been refetched.
316+
This method does not return anything
280317

281318
## `queryClient.resetQueries`
282319

@@ -297,10 +334,13 @@ queryClient.resetQueries(queryKey, { exact: true })
297334

298335
- `queryKey?: QueryKey`: [Query Keys](../guides/query-keys)
299336
- `filters?: QueryFilters`: [Query Filters](../guides/query-filters)
337+
- `resetOptions?: ResetOptions`:
338+
- `throwOnError?: boolean`
339+
- When set to `true`, this method will throw if any of the query refetch tasks fail.
300340

301341
**Returns**
302342

303-
This method does not return anything
343+
This method returns a promise that resolves when all active queries have been refetched.
304344

305345
## `queryClient.isFetching`
306346

@@ -415,4 +455,4 @@ The `clear` method clears all connected caches.
415455

416456
```js
417457
queryClient.clear()
418-
```
458+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@sveltestack/svelte-query",
33
"private": false,
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"description": "Hooks for managing, caching and syncing asynchronous and remote data in Svelte",
66
"license": "MIT",
77
"svelte": "svelte/index.js",

src/queryCore/core/query.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export class Query<
171171
this.clearGcTimeout()
172172

173173
if (isValidTimeout(this.cacheTime)) {
174-
// @ts-ignore
174+
// @ts-ignore
175175
this.gcTimeout = setTimeout(() => {
176176
this.optionalRemove()
177177
}, this.cacheTime)
@@ -465,18 +465,18 @@ export class Query<
465465

466466
const hasInitialData = typeof options.initialData !== 'undefined'
467467

468-
const initialDataUpdatedAt =
469-
hasInitialData &&
470-
(typeof options.initialDataUpdatedAt === 'function'
468+
const initialDataUpdatedAt = hasInitialData
469+
? typeof options.initialDataUpdatedAt === 'function'
471470
? (options.initialDataUpdatedAt as () => number | undefined)()
472-
: options.initialDataUpdatedAt)
471+
: options.initialDataUpdatedAt
472+
: 0
473473

474474
const hasData = typeof data !== 'undefined'
475475

476476
return {
477477
data,
478478
dataUpdateCount: 0,
479-
dataUpdatedAt: hasData ? initialDataUpdatedAt || Date.now() : 0,
479+
dataUpdatedAt: hasData ? initialDataUpdatedAt ?? Date.now() : 0,
480480
error: null,
481481
errorUpdateCount: 0,
482482
errorUpdatedAt: 0,

0 commit comments

Comments
 (0)