0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-18 19:33:22 +00:00
query/docs/framework/svelte/reference/functions/infiniteQueryOptions.md
Wonsuk Choi d169ee8778
docs(*): add property tables and overload overviews to reference pages and keep declared alias names (#11758)
* docs(*): add parameter and result property tables to reference function pages and an overview to overloaded ones

* docs(*): link to the base type's properties when a parameter or result type has no property table

* docs(framework/*/reference): regenerate reference docs

* docs(framework/*/reference): regenerate reference docs

* chore(scripts/generate-docs): restore the 'dirname' import that the merge dropped

* docs(framework/*/reference): regenerate reference docs

* docs(scripts/generate-docs): label overloads in the overview with their declared parameter and return types

* docs(framework/*/reference): regenerate reference docs

* docs(scripts/generate-docs): convert declared intersection types from the source so signatures keep their alias names

* docs(framework/*/reference): regenerate reference docs

* docs(scripts/generate-docs): reword a comment to avoid the unknown word 'inlines'

* docs(scripts/generate-docs): skip a parameter table on overloaded pages when its heading is missing
2026-10-06 02:38:27 +09:00

8.7 KiB

id title
infiniteQueryOptions infiniteQueryOptions

Overview

function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;

See also: Parameters · Returns

Call Signature

function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;

Defined in: packages/svelte-query/src/infiniteQueryOptions.ts:98

You can generally pass everything to infiniteQueryOptions that you can also pass to createInfiniteQuery. These options can be shared across createInfiniteQuery calls and imperative APIs such as queryClient.infiniteQuery. options.queryKey is required and is the query key to generate options for.

This overload is selected when initialData is known to be defined.

Type Parameters

TQueryFnData

TQueryFnData

TError

TError = Error

TData

TData = InfiniteData<TQueryFnData, unknown>

TQueryKey

TQueryKey extends readonly unknown[] = readonly unknown[]

TPageParam

TPageParam = unknown

Parameters

options

DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>

The DefinedInitialDataInfiniteOptions to use — everything you can pass to createInfiniteQuery, with initialData set.

Returns

DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>

The same options object, typed so that queryKey carries the inferred data type.

See

createInfiniteQuery to run an infinite query with these options.

Example

initialData skips the loading state on first render — even if a refetch fails, the list stays visible alongside the error:

<script lang="ts">
  import { infiniteQueryOptions, createInfiniteQuery } from '@tanstack/svelte-query'

  const projectsOptions = infiniteQueryOptions({
    queryKey: ['projects'],
    queryFn: ({ pageParam }) => fetchProjects(pageParam),
    initialPageParam: 0,
    getNextPageParam: (lastPage) => lastPage.nextId,
    initialData: { pages: [], pageParams: [] },
  })

  const query = createInfiniteQuery(() => projectsOptions)
</script>

{#if query.isError}
  <span>Error: {query.error.message}</span>
{/if}
<ul>
  {#each query.data.pages as page}
    {#each page.projects as project (project.id)}
      <li>{project.name}</li>
    {/each}
  {/each}
</ul>

Call Signature

function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;

Defined in: packages/svelte-query/src/infiniteQueryOptions.ts:163

You can generally pass everything to infiniteQueryOptions that you can also pass to createInfiniteQuery. These options can be shared across createInfiniteQuery calls and imperative APIs such as queryClient.infiniteQuery. options.queryKey is required and is the query key to generate options for.

Type Parameters

TQueryFnData

TQueryFnData

TError

TError = Error

TData

TData = InfiniteData<TQueryFnData, unknown>

TQueryKey

TQueryKey extends readonly unknown[] = readonly unknown[]

TPageParam

TPageParam = unknown

Parameters

options

UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>

The UndefinedInitialDataInfiniteOptions to use — everything you can pass to createInfiniteQuery.

Returns

UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>

The same options object, typed so that queryKey carries the inferred data type.

See

createInfiniteQuery to run an infinite query with these options.

Example

A parameterized factory, so the same options object can be reused per postId:

<script lang="ts">
  import { infiniteQueryOptions, createInfiniteQuery } from '@tanstack/svelte-query'

  let { postId }: { postId: string } = $props()

  const commentsOptions = (postId: string) =>
    infiniteQueryOptions({
      queryKey: ['post', postId, 'comments'],
      queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
      initialPageParam: 0,
      getNextPageParam: (lastPage) => lastPage.nextId,
    })

  const query = createInfiniteQuery(() => commentsOptions(postId))
</script>

{#if query.isPending}
  Loading...
{:else if query.isError}
  <span>Error: {query.error.message}</span>
{:else}
  <ul>
    {#each query.data.pages as page}
      {#each page.comments as comment (comment.id)}
        <li>{comment.text}</li>
      {/each}
    {/each}
  </ul>
{/if}

Parameters

options

UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>

The UndefinedInitialDataInfiniteOptions to use — everything you can pass to createInfiniteQuery.

options properties

Built from InfiniteQueryObserverOptions. See the type above for what it changes.

Returns

UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>

The same options object, typed so that queryKey carries the inferred data type.

Result properties

Built from InfiniteQueryObserverOptions, QueryKeyWithDataTag. See the type above for what it changes.