Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 44 additions & 3 deletions docs/framework/svelte/reference/functions/createInfiniteQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ title: createInfiniteQuery
function createInfiniteQuery<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: Accessor<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>>, queryClient?: Accessor<QueryClient>): DefinedCreateInfiniteQueryResult<TData, TError>;
```

Defined in: [packages/svelte-query/src/createInfiniteQuery.ts:21](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/createInfiniteQuery.ts#L21)
Defined in: [packages/svelte-query/src/createInfiniteQuery.ts:36](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/createInfiniteQuery.ts#L36)

The options for `createInfiniteQuery` are identical to `createQuery`, with the addition of
`initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.

This overload is selected when `initialData` is set.

### Type Parameters

Expand Down Expand Up @@ -39,21 +44,40 @@ Defined in: [packages/svelte-query/src/createInfiniteQuery.ts:21](https://github

[`Accessor`](../type-aliases/Accessor.md)\<[`DefinedInitialDataInfiniteOptions`](../type-aliases/DefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>\>

The [DefinedInitialDataInfiniteOptions](../type-aliases/DefinedInitialDataInfiniteOptions.md) to use β€” everything you can pass to
`createInfiniteQuery`, with `initialData` set, wrapped in an [Accessor](../type-aliases/Accessor.md) so options can be reactive.

#### queryClient?

[`Accessor`](../type-aliases/Accessor.md)\<[`QueryClient`](../classes/QueryClient.md)\>

Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
be used.

### Returns

[`DefinedCreateInfiniteQueryResult`](../type-aliases/DefinedCreateInfiniteQueryResult.md)\<`TData`, `TError`\>

The current query result, plus `fetchNextPage`/`fetchPreviousPage`/`hasNextPage`/`hasPreviousPage`
to page through the query.

### See

[infiniteQueryOptions](infiniteQueryOptions.md) to share these options between `createInfiniteQuery` and imperative APIs
like `queryClient.infiniteQuery`.

## Call Signature

```ts
function createInfiniteQuery<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: Accessor<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>>, queryClient?: Accessor<QueryClient>): CreateInfiniteQueryResult<TData, TError>;
```

Defined in: [packages/svelte-query/src/createInfiniteQuery.ts:40](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/createInfiniteQuery.ts#L40)
Defined in: [packages/svelte-query/src/createInfiniteQuery.ts:70](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/createInfiniteQuery.ts#L70)

The options for `createInfiniteQuery` are identical to `createQuery`, with the addition of
`initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.

This overload is selected when `initialData` is not set.

### Type Parameters

Expand Down Expand Up @@ -83,21 +107,38 @@ Defined in: [packages/svelte-query/src/createInfiniteQuery.ts:40](https://github

[`Accessor`](../type-aliases/Accessor.md)\<[`UndefinedInitialDataInfiniteOptions`](../type-aliases/UndefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>\>

The [UndefinedInitialDataInfiniteOptions](../type-aliases/UndefinedInitialDataInfiniteOptions.md) to use β€” everything you can pass to
`createInfiniteQuery`, wrapped in an [Accessor](../type-aliases/Accessor.md) so options can be reactive.

#### queryClient?

[`Accessor`](../type-aliases/Accessor.md)\<[`QueryClient`](../classes/QueryClient.md)\>

Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
be used.

### Returns

[`CreateInfiniteQueryResult`](../type-aliases/CreateInfiniteQueryResult.md)\<`TData`, `TError`\>

The current query result, plus `fetchNextPage`/`fetchPreviousPage`/`hasNextPage`/`hasPreviousPage`
to page through the query.

### See

[infiniteQueryOptions](infiniteQueryOptions.md) to share these options between `createInfiniteQuery` and imperative APIs
like `queryClient.infiniteQuery`.

## Call Signature

```ts
function createInfiniteQuery<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: Accessor<CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>>, queryClient?: Accessor<QueryClient>): CreateInfiniteQueryResult<TData, TError>;
```

Defined in: [packages/svelte-query/src/createInfiniteQuery.ts:152](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/createInfiniteQuery.ts#L152)
Defined in: [packages/svelte-query/src/createInfiniteQuery.ts:185](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/createInfiniteQuery.ts#L185)

The options for `createInfiniteQuery` are identical to `createQuery`, with the addition of
`initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.

### Type Parameters

Expand Down
4 changes: 3 additions & 1 deletion docs/framework/svelte/reference/functions/createQueries.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ function createQueries<T, TCombinedResult>(createQueriesOptions: Accessor<{
}>, queryClient?: Accessor<QueryClient>): TCombinedResult;
```

Defined in: [packages/svelte-query/src/createQueries.svelte.ts:260](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/createQueries.svelte.ts#L260)
Defined in: [packages/svelte-query/src/createQueries.svelte.ts:262](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/createQueries.svelte.ts#L262)

The `createQueries` function can be used to fetch a variable number of queries.

## Type Parameters

Expand Down
12 changes: 9 additions & 3 deletions docs/framework/svelte/reference/functions/createQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ title: createQuery
function createQuery<TQueryFnData, TError, TData, TQueryKey>(options: Accessor<UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>>, queryClient?: Accessor<QueryClient>): CreateQueryResult<TData, TError>;
```

Defined in: [packages/svelte-query/src/createQuery.ts:74](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/createQuery.ts#L74)
Defined in: [packages/svelte-query/src/createQuery.ts:77](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/createQuery.ts#L77)

Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
The query runs when the options call for it β€” `enabled: false` skips the initial fetch.

### Type Parameters

Expand Down Expand Up @@ -112,7 +115,10 @@ The same query, checking `isPending`/`isError` instead of `status` β€” pick whic
function createQuery<TQueryFnData, TError, TData, TQueryKey>(options: Accessor<DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>>, queryClient?: Accessor<QueryClient>): DefinedCreateQueryResult<TData, TError>;
```

Defined in: [packages/svelte-query/src/createQuery.ts:122](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/createQuery.ts#L122)
Defined in: [packages/svelte-query/src/createQuery.ts:128](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/createQuery.ts#L128)

Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
The query runs when the options call for it β€” `enabled: false` skips the initial fetch.

This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.

Expand Down Expand Up @@ -193,7 +199,7 @@ since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived
function createQuery<TQueryFnData, TError, TData, TQueryKey>(options: Accessor<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>>, queryClient?: Accessor<QueryClient>): CreateQueryResult<TData, TError>;
```

Defined in: [packages/svelte-query/src/createQuery.ts:248](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/createQuery.ts#L248)
Defined in: [packages/svelte-query/src/createQuery.ts:254](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/createQuery.ts#L254)

### Type Parameters

Expand Down
5 changes: 4 additions & 1 deletion docs/framework/svelte/reference/functions/useIsFetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ title: useIsFetching
function useIsFetching(filters?: QueryFilters<readonly unknown[]>, queryClient?: QueryClient): ReactiveValue<number>;
```

Defined in: [packages/svelte-query/src/useIsFetching.svelte.ts:40](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/useIsFetching.svelte.ts#L40)
Defined in: [packages/svelte-query/src/useIsFetching.svelte.ts:43](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/useIsFetching.svelte.ts#L43)

The `useIsFetching` function returns the `number` of the queries that your application is loading or
fetching in the background (useful for app-wide loading indicators).

## Parameters

Expand Down
23 changes: 22 additions & 1 deletion docs/framework/svelte/reference/functions/useIsRestoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,29 @@ title: useIsRestoring
function useIsRestoring(): Box<boolean>;
```

Defined in: [packages/svelte-query/src/useIsRestoring.ts:4](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/useIsRestoring.ts#L4)
Defined in: [packages/svelte-query/src/useIsRestoring.ts:24](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/useIsRestoring.ts#L24)

If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` function alongside it to
check if a restore is currently in progress. `createQuery` and friends also check this internally to avoid
race conditions between the restore and mounting queries.

## Returns

`Box`\<`boolean`\>

A reactive box β€” read `.current` for `true` while a persisted client is being restored, `false`
otherwise.

## Example

```svelte
<script lang="ts">
import { useIsRestoring } from '@tanstack/svelte-query'

const isRestoring = useIsRestoring()
</script>

{#if isRestoring.current}
<div>Restoring cached data...</div>
{/if}
```
27 changes: 26 additions & 1 deletion docs/framework/svelte/reference/functions/useQueryClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,39 @@ title: useQueryClient
function useQueryClient(queryClient?: QueryClient): QueryClient;
```

Defined in: [packages/svelte-query/src/useQueryClient.ts:4](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/useQueryClient.ts#L4)
Defined in: [packages/svelte-query/src/useQueryClient.ts:24](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/useQueryClient.ts#L24)

The `useQueryClient` function returns the current `QueryClient` instance.

## Parameters

### queryClient?

[`QueryClient`](../classes/QueryClient.md)

Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
be used.

## Returns

[`QueryClient`](../classes/QueryClient.md)

The current `QueryClient` instance.

## Throws

If no `queryClient` argument is passed and no `QueryClientProvider` is found in the component tree.

## Example

```svelte
<script lang="ts">
import { useQueryClient } from '@tanstack/svelte-query'

const queryClient = useQueryClient()

function refreshPosts() {
queryClient.invalidateQueries({ queryKey: ['posts'] })
}
</script>
```
33 changes: 33 additions & 0 deletions packages/svelte-query/src/createInfiniteQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ import type {
UndefinedInitialDataInfiniteOptions,
} from './infiniteQueryOptions.js'

/**
* The options for `createInfiniteQuery` are identical to `createQuery`, with the addition of
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
*
* This overload is selected when `initialData` is set.
*
* @see {@link infiniteQueryOptions} to share these options between `createInfiniteQuery` and imperative APIs
* like `queryClient.infiniteQuery`.
* @param options - The {@link DefinedInitialDataInfiniteOptions} to use β€” everything you can pass to
* `createInfiniteQuery`, with `initialData` set, wrapped in an {@link Accessor} so options can be reactive.
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
* be used.
* @returns The current query result, plus `fetchNextPage`/`fetchPreviousPage`/`hasNextPage`/`hasPreviousPage`
* to page through the query.
*/
export function createInfiniteQuery<
TQueryFnData = unknown,
TError = DefaultError,
Expand All @@ -37,6 +52,21 @@ export function createInfiniteQuery<
queryClient?: Accessor<QueryClient>,
): DefinedCreateInfiniteQueryResult<TData, TError>

/**
* The options for `createInfiniteQuery` are identical to `createQuery`, with the addition of
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
*
* This overload is selected when `initialData` is not set.
*
* @see {@link infiniteQueryOptions} to share these options between `createInfiniteQuery` and imperative APIs
* like `queryClient.infiniteQuery`.
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use β€” everything you can pass to
* `createInfiniteQuery`, wrapped in an {@link Accessor} so options can be reactive.
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
* be used.
* @returns The current query result, plus `fetchNextPage`/`fetchPreviousPage`/`hasNextPage`/`hasPreviousPage`
* to page through the query.
*/
export function createInfiniteQuery<
TQueryFnData = unknown,
TError = DefaultError,
Expand All @@ -57,6 +87,9 @@ export function createInfiniteQuery<
): CreateInfiniteQueryResult<TData, TError>

/**
* The options for `createInfiniteQuery` are identical to `createQuery`, with the addition of
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
*
* @see {@link infiniteQueryOptions} to share these options between `createInfiniteQuery` and imperative APIs
* like `queryClient.infiniteQuery`.
* @param options - The {@link CreateInfiniteQueryOptions} to use β€” everything you can pass to
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte-query/src/createQueries.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ export type QueriesResults<
: { [K in keyof T]: GetCreateQueryResult<T[K]> }

/**
* The `createQueries` function can be used to fetch a variable number of queries.
*
* @param createQueriesOptions - The `queries` array to run, and an optional `combine` function, wrapped in an
* {@link Accessor} so options can be reactive.
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context
Expand Down
6 changes: 6 additions & 0 deletions packages/svelte-query/src/createQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import type {
} from './queryOptions.js'

/**
* Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
* The query runs when the options call for it β€” `enabled: false` skips the initial fetch.
*
* @see {@link queryOptions} to share these options between `createQuery` and imperative APIs like `queryClient.query`.
* @param options - The {@link UndefinedInitialDataOptions} to use β€” everything you can pass to `createQuery`,
* wrapped in an {@link Accessor} so options can be reactive.
Expand Down Expand Up @@ -84,6 +87,9 @@ export function createQuery<
): CreateQueryResult<TData, TError>

/**
* Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
* The query runs when the options call for it β€” `enabled: false` skips the initial fetch.
*
* This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
*
* @see {@link queryOptions} to share these options between `createQuery` and imperative APIs like `queryClient.query`.
Expand Down
3 changes: 3 additions & 0 deletions packages/svelte-query/src/useIsFetching.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { useQueryClient } from './useQueryClient.js'
import type { QueryClient, QueryFilters } from '@tanstack/query-core'

/**
* The `useIsFetching` function returns the `number` of the queries that your application is loading or
* fetching in the background (useful for app-wide loading indicators).
*
* @param filters - {@link QueryFilters} to narrow down which queries to count. Omit to count every fetching
* query.
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
Expand Down
20 changes: 20 additions & 0 deletions packages/svelte-query/src/useIsRestoring.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import { getIsRestoringContext } from './context.js'
import type { Box } from './containers.svelte.js'

/**
* If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` function alongside it to
* check if a restore is currently in progress. `createQuery` and friends also check this internally to avoid
* race conditions between the restore and mounting queries.
*
* @returns A reactive box β€” read `.current` for `true` while a persisted client is being restored, `false`
* otherwise.
* @example
* ```svelte
* <script lang="ts">
* import { useIsRestoring } from '@tanstack/svelte-query'
*
* const isRestoring = useIsRestoring()
* </script>
*
* {#if isRestoring.current}
* <div>Restoring cached data...</div>
* {/if}
* ```
*/
export function useIsRestoring(): Box<boolean> {
return getIsRestoringContext()
}
20 changes: 20 additions & 0 deletions packages/svelte-query/src/useQueryClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import { getQueryClientContext } from './context.js'
import type { QueryClient } from '@tanstack/query-core'

/**
* The `useQueryClient` function returns the current `QueryClient` instance.
*
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
* be used.
* @returns The current `QueryClient` instance.
* @throws If no `queryClient` argument is passed and no `QueryClientProvider` is found in the component tree.
* @example
* ```svelte
* <script lang="ts">
* import { useQueryClient } from '@tanstack/svelte-query'
*
* const queryClient = useQueryClient()
*
* function refreshPosts() {
* queryClient.invalidateQueries({ queryKey: ['posts'] })
* }
* </script>
* ```
*/
export function useQueryClient(queryClient?: QueryClient): QueryClient {
if (queryClient) return queryClient
return getQueryClientContext()
Expand Down
Loading