snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
---
|
||||
id: IsRestoringProvider
|
||||
title: IsRestoringProvider
|
||||
---
|
||||
|
||||
```ts
|
||||
const IsRestoringProvider: ContextProviderComponent<Accessor<boolean>> = IsRestoringContext.Provider;
|
||||
```
|
||||
|
||||
Defined in: [packages/solid-query/src/isRestoring.ts:19](https://github.com/TanStack/query/blob/main/packages/solid-query/src/isRestoring.ts#L19)
|
||||
|
||||
The Provider that `PersistQueryClientProvider` uses to signal whether a persisted client is currently
|
||||
being restored, read by `useIsRestoring`.
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
id: QueryClientContext
|
||||
title: QueryClientContext
|
||||
---
|
||||
|
||||
```ts
|
||||
const QueryClientContext: Context<() => QueryClient | undefined>;
|
||||
```
|
||||
|
||||
Defined in: [packages/solid-query/src/QueryClientProvider.tsx:13](https://github.com/TanStack/query/blob/main/packages/solid-query/src/QueryClientProvider.tsx#L13)
|
||||
|
||||
The context that `useQueryClient` reads from. `QueryClientProvider` is the normal way to set it.
|
||||
262
docs/framework/solid/reference/variables/createInfiniteQuery.md
Normal file
262
docs/framework/solid/reference/variables/createInfiniteQuery.md
Normal file
@@ -0,0 +1,262 @@
|
||||
---
|
||||
id: createInfiniteQuery
|
||||
title: createInfiniteQuery
|
||||
---
|
||||
|
||||
```ts
|
||||
const createInfiniteQuery: {
|
||||
<TQueryFnData, TError, TData, TQueryKey, TPageParam> (options, queryClient?): DefinedUseInfiniteQueryResult<TData, TError>;
|
||||
<TQueryFnData, TError, TData, TQueryKey, TPageParam> (options, queryClient?): UseInfiniteQueryResult<TData, TError>;
|
||||
} = useInfiniteQuery;
|
||||
```
|
||||
|
||||
Defined in: [packages/solid-query/src/index.ts:72](https://github.com/TanStack/query/blob/main/packages/solid-query/src/index.ts#L72)
|
||||
|
||||
## Call Signature
|
||||
|
||||
```ts
|
||||
<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options, queryClient?): DefinedUseInfiniteQueryResult<TData, TError>;
|
||||
```
|
||||
|
||||
The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of
|
||||
`initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
||||
|
||||
This overload is selected when `initialData` is set.
|
||||
|
||||
### Type Parameters
|
||||
|
||||
#### TQueryFnData
|
||||
|
||||
`TQueryFnData`
|
||||
|
||||
#### TError
|
||||
|
||||
`TError` = `Error`
|
||||
|
||||
#### TData
|
||||
|
||||
`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
|
||||
|
||||
#### TQueryKey
|
||||
|
||||
`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
|
||||
|
||||
#### TPageParam
|
||||
|
||||
`TPageParam` = `unknown`
|
||||
|
||||
### Parameters
|
||||
|
||||
#### options
|
||||
|
||||
[`DefinedInitialDataInfiniteOptions`](../type-aliases/DefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
|
||||
|
||||
An accessor returning the [DefinedInitialDataInfiniteOptions](../type-aliases/DefinedInitialDataInfiniteOptions.md) to use — everything you
|
||||
can pass to `useInfiniteQuery`, with `initialData` set.
|
||||
|
||||
#### queryClient?
|
||||
|
||||
`Accessor`\<[`QueryClient`](../classes/QueryClient.md)\>
|
||||
|
||||
An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
||||
will be used.
|
||||
|
||||
### Returns
|
||||
|
||||
[`DefinedUseInfiniteQueryResult`](../type-aliases/DefinedUseInfiniteQueryResult.md)\<`TData`, `TError`\>
|
||||
|
||||
The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,
|
||||
`hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
|
||||
`data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
||||
`InfiniteData<TQueryFnData>` shape.
|
||||
|
||||
### Remarks
|
||||
|
||||
Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
||||
refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
||||
actions, or add conditions like `hasNextPage && !isFetching`.
|
||||
|
||||
### See
|
||||
|
||||
[infiniteQueryOptions](../functions/infiniteQueryOptions.md) to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
||||
|
||||
### Example
|
||||
|
||||
```tsx
|
||||
import { For } from 'solid-js'
|
||||
import { useInfiniteQuery } from '@tanstack/solid-query'
|
||||
|
||||
function Projects() {
|
||||
// `projectsQuery.data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the
|
||||
// list stays visible alongside the error.
|
||||
const projectsQuery = useInfiniteQuery(() => ({
|
||||
queryKey: ['projects'],
|
||||
queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
||||
initialPageParam: 0,
|
||||
getNextPageParam: (lastPage) => lastPage.nextId,
|
||||
initialData: { pages: [], pageParams: [] },
|
||||
}))
|
||||
|
||||
return (
|
||||
<div>
|
||||
{projectsQuery.isError ? <span>Error: {projectsQuery.error.message}</span> : null}
|
||||
<ul>
|
||||
<For each={projectsQuery.data.pages}>
|
||||
{(page) => <For each={page.projects}>{(p) => <li>{p.name}</li>}</For>}
|
||||
</For>
|
||||
</ul>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
## Call Signature
|
||||
|
||||
```ts
|
||||
<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options, queryClient?): UseInfiniteQueryResult<TData, TError>;
|
||||
```
|
||||
|
||||
The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of
|
||||
`initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
||||
|
||||
### Type Parameters
|
||||
|
||||
#### TQueryFnData
|
||||
|
||||
`TQueryFnData`
|
||||
|
||||
#### TError
|
||||
|
||||
`TError` = `Error`
|
||||
|
||||
#### TData
|
||||
|
||||
`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
|
||||
|
||||
#### TQueryKey
|
||||
|
||||
`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
|
||||
|
||||
#### TPageParam
|
||||
|
||||
`TPageParam` = `unknown`
|
||||
|
||||
### Parameters
|
||||
|
||||
#### options
|
||||
|
||||
[`UndefinedInitialDataInfiniteOptions`](../type-aliases/UndefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
|
||||
|
||||
An accessor returning the [UndefinedInitialDataInfiniteOptions](../type-aliases/UndefinedInitialDataInfiniteOptions.md) to use — everything
|
||||
you can pass to `useInfiniteQuery`.
|
||||
|
||||
#### queryClient?
|
||||
|
||||
`Accessor`\<[`QueryClient`](../classes/QueryClient.md)\>
|
||||
|
||||
An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
||||
will be used.
|
||||
|
||||
### Returns
|
||||
|
||||
[`UseInfiniteQueryResult`](../type-aliases/UseInfiniteQueryResult.md)\<`TData`, `TError`\>
|
||||
|
||||
The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,
|
||||
`hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
|
||||
`data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
||||
`InfiniteData<TQueryFnData>` shape.
|
||||
|
||||
### Remarks
|
||||
|
||||
Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
||||
refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
||||
actions, or add conditions like `hasNextPage && !isFetching`.
|
||||
|
||||
### See
|
||||
|
||||
[infiniteQueryOptions](../functions/infiniteQueryOptions.md) to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
||||
|
||||
### Examples
|
||||
|
||||
Fetching the next page from a "Load More" button click:
|
||||
```tsx
|
||||
import { For, Match, Switch } from 'solid-js'
|
||||
import { useInfiniteQuery } from '@tanstack/solid-query'
|
||||
|
||||
function Projects() {
|
||||
const projectsQuery = useInfiniteQuery(() => ({
|
||||
queryKey: ['projects'],
|
||||
queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
||||
initialPageParam: 0,
|
||||
getNextPageParam: (lastPage) => lastPage.nextId,
|
||||
}))
|
||||
|
||||
return (
|
||||
<Switch>
|
||||
<Match when={projectsQuery.isPending}>Loading...</Match>
|
||||
<Match when={projectsQuery.isError}>Error: {projectsQuery.error.message}</Match>
|
||||
<Match when={projectsQuery.isSuccess}>
|
||||
<ul>
|
||||
<For each={projectsQuery.data.pages}>
|
||||
{(page) => <For each={page.projects}>{(p) => <li>{p.name}</li>}</For>}
|
||||
</For>
|
||||
</ul>
|
||||
<button
|
||||
onClick={() => projectsQuery.fetchNextPage()}
|
||||
disabled={!projectsQuery.hasNextPage || projectsQuery.isFetching}
|
||||
>
|
||||
{projectsQuery.isFetchingNextPage
|
||||
? 'Loading more...'
|
||||
: projectsQuery.hasNextPage
|
||||
? 'Load More'
|
||||
: 'Nothing more to load'}
|
||||
</button>
|
||||
</Match>
|
||||
</Switch>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a
|
||||
sentinel element after the list:
|
||||
```tsx
|
||||
import { For, Match, Switch, createEffect, onCleanup } from 'solid-js'
|
||||
import { useInfiniteQuery } from '@tanstack/solid-query'
|
||||
|
||||
function Projects() {
|
||||
const projectsQuery = useInfiniteQuery(() => ({
|
||||
queryKey: ['projects'],
|
||||
queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
||||
initialPageParam: 0,
|
||||
getNextPageParam: (lastPage) => lastPage.nextId,
|
||||
}))
|
||||
|
||||
let sentinelRef: HTMLDivElement | undefined
|
||||
|
||||
createEffect(() => {
|
||||
if (sentinelRef == null || !projectsQuery.hasNextPage || projectsQuery.isFetching) return
|
||||
|
||||
const observer = new IntersectionObserver(([entry]) => {
|
||||
if (entry?.isIntersecting) projectsQuery.fetchNextPage()
|
||||
})
|
||||
observer.observe(sentinelRef)
|
||||
|
||||
onCleanup(() => observer.disconnect())
|
||||
})
|
||||
|
||||
return (
|
||||
<Switch>
|
||||
<Match when={projectsQuery.isPending}>Loading...</Match>
|
||||
<Match when={projectsQuery.isError}>Error: {projectsQuery.error.message}</Match>
|
||||
<Match when={projectsQuery.isSuccess}>
|
||||
<ul>
|
||||
<For each={projectsQuery.data.pages}>
|
||||
{(page) => <For each={page.projects}>{(p) => <li>{p.name}</li>}</For>}
|
||||
</For>
|
||||
</ul>
|
||||
<div ref={sentinelRef}>{projectsQuery.isFetchingNextPage ? 'Loading more...' : null}</div>
|
||||
</Match>
|
||||
</Switch>
|
||||
)
|
||||
}
|
||||
```
|
||||
199
docs/framework/solid/reference/variables/createMutation.md
Normal file
199
docs/framework/solid/reference/variables/createMutation.md
Normal file
@@ -0,0 +1,199 @@
|
||||
---
|
||||
id: createMutation
|
||||
title: createMutation
|
||||
---
|
||||
|
||||
```ts
|
||||
const createMutation: <TData, TError, TVariables, TOnMutateResult>(options, queryClient?) => UseMutationResult<TData, TError, TVariables, TOnMutateResult> = useMutation;
|
||||
```
|
||||
|
||||
Defined in: [packages/solid-query/src/index.ts:80](https://github.com/TanStack/query/blob/main/packages/solid-query/src/index.ts#L80)
|
||||
|
||||
## Type Parameters
|
||||
|
||||
### TData
|
||||
|
||||
`TData` = `unknown`
|
||||
|
||||
### TError
|
||||
|
||||
`TError` = `Error`
|
||||
|
||||
### TVariables
|
||||
|
||||
`TVariables` = `void`
|
||||
|
||||
### TOnMutateResult
|
||||
|
||||
`TOnMutateResult` = `unknown`
|
||||
|
||||
## Parameters
|
||||
|
||||
### options
|
||||
|
||||
[`UseMutationOptions`](../type-aliases/UseMutationOptions.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>
|
||||
|
||||
An accessor returning the [UseMutationOptions](../type-aliases/UseMutationOptions.md) to use.
|
||||
|
||||
### queryClient?
|
||||
|
||||
`Accessor`\<[`QueryClient`](../classes/QueryClient.md)\>
|
||||
|
||||
An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
||||
will be used.
|
||||
|
||||
## Returns
|
||||
|
||||
[`UseMutationResult`](../type-aliases/UseMutationResult.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>
|
||||
|
||||
`mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second
|
||||
argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared
|
||||
mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call callbacks
|
||||
fire only for the latest call you've made, and only while the component is still mounted — unmounting before
|
||||
the mutation settles removes the subscription and prevents them from firing.
|
||||
|
||||
## Examples
|
||||
|
||||
```tsx
|
||||
import { useMutation, useQueryClient } from '@tanstack/solid-query'
|
||||
|
||||
function TodoItem(props: { id: number }) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const deleteTodoMutation = useMutation(() => ({
|
||||
mutationFn: deleteTodo,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['todos'] })
|
||||
},
|
||||
}))
|
||||
|
||||
return (
|
||||
<button onClick={() => deleteTodoMutation.mutate({ id: props.id })} disabled={deleteTodoMutation.isPending}>
|
||||
Delete
|
||||
</button>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
Rendering the mutation's own state, rather than just firing it off:
|
||||
```tsx
|
||||
import { Match, Switch } from 'solid-js'
|
||||
import { useMutation, useQueryClient } from '@tanstack/solid-query'
|
||||
|
||||
function AddTodo() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const addMutation = useMutation(() => ({
|
||||
mutationFn: addTodo,
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
|
||||
}))
|
||||
|
||||
return (
|
||||
<Switch fallback={<button onClick={() => addMutation.mutate('Item')}>Add</button>}>
|
||||
<Match when={addMutation.isPending}>Adding todo...</Match>
|
||||
<Match when={addMutation.isError}>
|
||||
<div>An error occurred: {addMutation.error?.message}</div>
|
||||
<button onClick={() => addMutation.mutate('Item')}>Add</button>
|
||||
</Match>
|
||||
</Switch>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
Optimistic update via `onMutate`, rolling back on `onError`:
|
||||
```tsx
|
||||
import { useMutation, useQueryClient } from '@tanstack/solid-query'
|
||||
|
||||
function AddTodo() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const addMutation = useMutation(() => ({
|
||||
mutationFn: addTodo,
|
||||
onMutate: async (newTodo) => {
|
||||
await queryClient.cancelQueries({ queryKey: ['todos'] })
|
||||
const previousTodos = queryClient.getQueryData<Array<string>>(['todos'])
|
||||
|
||||
queryClient.setQueryData<Array<string>>(['todos'], (old) => [
|
||||
...(old ?? []),
|
||||
newTodo,
|
||||
])
|
||||
|
||||
// Passed to `onError` as `onMutateResult` if the mutation fails.
|
||||
return { previousTodos }
|
||||
},
|
||||
onError: (_err, _newTodo, onMutateResult) => {
|
||||
queryClient.setQueryData(['todos'], onMutateResult?.previousTodos)
|
||||
},
|
||||
onSettled: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['todos'] })
|
||||
},
|
||||
}))
|
||||
|
||||
return (
|
||||
<button onClick={() => addMutation.mutate('Item')}>Add</button>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
|
||||
promise per call instead, so you can wait for all of them when they succeed:
|
||||
```tsx
|
||||
import { useMutation, useQueryClient } from '@tanstack/solid-query'
|
||||
|
||||
function AddTodos() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const addMutation = useMutation(() => ({
|
||||
mutationFn: addTodo,
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
|
||||
}))
|
||||
|
||||
async function handleAddAll(todos: Array<string>) {
|
||||
try {
|
||||
await Promise.all(todos.map((todo) => addMutation.mutateAsync(todo)))
|
||||
} catch (error) {
|
||||
console.error('Failed to add todos:', error)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<button onClick={() => handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])}>
|
||||
Add all
|
||||
</button>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
If some of the mutations above can fail independently of the others, and you want to know which ones
|
||||
did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
|
||||
`Promise.allSettled`:
|
||||
```tsx
|
||||
import { useMutation, useQueryClient } from '@tanstack/solid-query'
|
||||
|
||||
function AddTodos() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const addMutation = useMutation(() => ({
|
||||
mutationFn: addTodo,
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
|
||||
}))
|
||||
|
||||
async function handleAddAll(todos: Array<string>) {
|
||||
const addResults = await Promise.allSettled(
|
||||
todos.map((todo) => addMutation.mutateAsync(todo)),
|
||||
)
|
||||
|
||||
addResults.forEach((addResult, index) => {
|
||||
if (addResult.status === 'rejected') {
|
||||
console.error(`Failed to add "${todos[index]}":`, addResult.reason)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<button onClick={() => handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])}>
|
||||
Add all
|
||||
</button>
|
||||
)
|
||||
}
|
||||
```
|
||||
154
docs/framework/solid/reference/variables/createQueries.md
Normal file
154
docs/framework/solid/reference/variables/createQueries.md
Normal file
@@ -0,0 +1,154 @@
|
||||
---
|
||||
id: createQueries
|
||||
title: createQueries
|
||||
---
|
||||
|
||||
```ts
|
||||
const createQueries: <T, TCombinedResult>(queriesOptions, queryClient?) => TCombinedResult = useQueries;
|
||||
```
|
||||
|
||||
Defined in: [packages/solid-query/src/index.ts:86](https://github.com/TanStack/query/blob/main/packages/solid-query/src/index.ts#L86)
|
||||
|
||||
The `useQueries` hook can be used to fetch a variable number of queries.
|
||||
|
||||
The `queries` key accepts an array with query option objects mostly identical to `useQuery` — see
|
||||
`placeholderData` below for the one difference. A custom `QueryClient` is supplied once, as `useQueries`'
|
||||
own top-level second argument, rather than per query.
|
||||
|
||||
Having the same query key more than once in the array of query objects may cause some data to be shared
|
||||
between queries. To avoid this, consider de-duplicating the queries and map the results back to the desired
|
||||
structure.
|
||||
|
||||
The `combine` option can be used to combine the results of the queries into a single value. The result will
|
||||
be structurally shared to be as referentially stable as possible.
|
||||
|
||||
`placeholderData` is supported here too, but unlike `useQuery`, it doesn't receive information from
|
||||
previously rendered queries, because the number of queries can differ between renders.
|
||||
|
||||
## Type Parameters
|
||||
|
||||
### T
|
||||
|
||||
`T` *extends* `any`[]
|
||||
|
||||
### TCombinedResult
|
||||
|
||||
`TCombinedResult` *extends*
|
||||
\| \[\]
|
||||
\| \[
|
||||
\| [`QueryObserverRefetchErrorResult`](../interfaces/QueryObserverRefetchErrorResult.md)\<`unknown`, `Error`\>
|
||||
\| [`QueryObserverSuccessResult`](../interfaces/QueryObserverSuccessResult.md)\<`unknown`, `Error`\>
|
||||
\| [`QueryObserverLoadingErrorResult`](../interfaces/QueryObserverLoadingErrorResult.md)\<`unknown`, `Error`\>
|
||||
\| [`QueryObserverLoadingResult`](../interfaces/QueryObserverLoadingResult.md)\<`unknown`, `Error`\>
|
||||
\| [`QueryObserverPendingResult`](../interfaces/QueryObserverPendingResult.md)\<`unknown`, `Error`\>
|
||||
\| [`QueryObserverPlaceholderResult`](../interfaces/QueryObserverPlaceholderResult.md)\<`unknown`, `Error`\>
|
||||
\| [`QueryObserverRefetchErrorResult`](../interfaces/QueryObserverRefetchErrorResult.md)\<`unknown`, `unknown`\>
|
||||
\| [`QueryObserverSuccessResult`](../interfaces/QueryObserverSuccessResult.md)\<`unknown`, `unknown`\>
|
||||
\| [`QueryObserverLoadingErrorResult`](../interfaces/QueryObserverLoadingErrorResult.md)\<`unknown`, `unknown`\>
|
||||
\| [`QueryObserverLoadingResult`](../interfaces/QueryObserverLoadingResult.md)\<`unknown`, `unknown`\>
|
||||
\| [`QueryObserverPendingResult`](../interfaces/QueryObserverPendingResult.md)\<`unknown`, `unknown`\>
|
||||
\| [`QueryObserverPlaceholderResult`](../interfaces/QueryObserverPlaceholderResult.md)\<`unknown`, `unknown`\>\]
|
||||
\| (
|
||||
\| [`QueryObserverRefetchErrorResult`](../interfaces/QueryObserverRefetchErrorResult.md)\<`unknown`, `Error`\>
|
||||
\| [`QueryObserverSuccessResult`](../interfaces/QueryObserverSuccessResult.md)\<`unknown`, `Error`\>
|
||||
\| [`QueryObserverLoadingErrorResult`](../interfaces/QueryObserverLoadingErrorResult.md)\<`unknown`, `Error`\>
|
||||
\| [`QueryObserverLoadingResult`](../interfaces/QueryObserverLoadingResult.md)\<`unknown`, `Error`\>
|
||||
\| [`QueryObserverPendingResult`](../interfaces/QueryObserverPendingResult.md)\<`unknown`, `Error`\>
|
||||
\| [`QueryObserverPlaceholderResult`](../interfaces/QueryObserverPlaceholderResult.md)\<`unknown`, `Error`\>
|
||||
\| [`QueryObserverRefetchErrorResult`](../interfaces/QueryObserverRefetchErrorResult.md)\<`unknown`, `unknown`\>
|
||||
\| [`QueryObserverSuccessResult`](../interfaces/QueryObserverSuccessResult.md)\<`unknown`, `unknown`\>
|
||||
\| [`QueryObserverLoadingErrorResult`](../interfaces/QueryObserverLoadingErrorResult.md)\<`unknown`, `unknown`\>
|
||||
\| [`QueryObserverLoadingResult`](../interfaces/QueryObserverLoadingResult.md)\<`unknown`, `unknown`\>
|
||||
\| [`QueryObserverPendingResult`](../interfaces/QueryObserverPendingResult.md)\<`unknown`, `unknown`\>
|
||||
\| [`QueryObserverPlaceholderResult`](../interfaces/QueryObserverPlaceholderResult.md)\<`unknown`, `unknown`\>)[] = `T` *extends* \[\] ? \[\] : `T` *extends* \[`Head`\] ? \[`GetResults`\<`Head`\>\] : `T` *extends* \[`Head`, `...Tail[]`\] ? \[`...Tail[]`\] *extends* \[\] ? \[\] : \[`...Tail[]`\] *extends* \[`Head`\] ? \[`GetResults`\<`Head`\>, `GetResults`\<`Head`\>\] : \[`...Tail[]`\] *extends* \[`Head`, `...Tail[]`\] ? \[`...Tail[]`\] *extends* \[\] ? \[\] : \[`...Tail[]`\] *extends* \[`Head`\] ? \[`GetResults`\<...\>, `GetResults`\<...\>, `GetResults`\<...\>\] : \[`...(...)[]`\] *extends* \[..., `...(...)[]`\] ? ... *extends* ... ? ... : ... : \[`...(...)[]`\] : \[...\{ \[K in string \| number \| symbol\]: GetResults\<(...)\[(...)\]\> \}\[\]\] : \{ \[K in string \| number \| symbol\]: GetResults\<T\[K\<K\>\]\> \}
|
||||
|
||||
## Parameters
|
||||
|
||||
### queriesOptions
|
||||
|
||||
`Accessor`\<\{
|
||||
`combine?`: (`result`) => `TCombinedResult`;
|
||||
`queries`: \| readonly \[`T` *extends* \[\] ? \[\] : `T` *extends* \[`Head`\] ? \[`GetOptions`\<`Head`\>\] : `T` *extends* \[`Head`, `...Tail[]`\] ? \[`...Tail[]`\] *extends* \[\] ? \[\] : \[`...(...)[]`\] *extends* \[...\] ? \[..., ...\] : ... *extends* ... ? ... : ... : readonly `unknown`[] *extends* `T` ? `T` : `T` *extends* ...[] ? ...[] : ...[]\]
|
||||
\| readonly \[\{ \[K in string \| number \| symbol\]: GetOptions\<T\[K\<K\>\]\> \}\];
|
||||
\}\>
|
||||
|
||||
An accessor returning the `queries` array to run, and an optional `combine`
|
||||
function.
|
||||
|
||||
### queryClient?
|
||||
|
||||
`Accessor`\<[`QueryClient`](../classes/QueryClient.md)\>
|
||||
|
||||
An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
||||
will be used.
|
||||
|
||||
## Returns
|
||||
|
||||
`TCombinedResult`
|
||||
|
||||
The combined result. Without `combine`, this is an array with all the query results, in the same
|
||||
order as the input. When `combine` is provided, this is the value returned by `combine` instead.
|
||||
|
||||
## Examples
|
||||
|
||||
```tsx
|
||||
import { For } from 'solid-js'
|
||||
import { useQueries } from '@tanstack/solid-query'
|
||||
|
||||
function Posts(props: { ids: Array<number> }) {
|
||||
const postQueries = useQueries(() => ({
|
||||
queries: props.ids.map((id) => ({
|
||||
queryKey: ['post', id],
|
||||
queryFn: () => fetchPost(id),
|
||||
staleTime: Infinity,
|
||||
})),
|
||||
}))
|
||||
|
||||
return (
|
||||
<ul>
|
||||
<For each={postQueries}>
|
||||
{(postQuery) => {
|
||||
if (postQuery.isPending) return <li>Loading...</li>
|
||||
if (postQuery.isError) return <li>Error: {postQuery.error.message}</li>
|
||||
return <li>{postQuery.data.title}</li>
|
||||
}}
|
||||
</For>
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
Combining results into a single value:
|
||||
```tsx
|
||||
import { For, Match, Switch } from 'solid-js'
|
||||
import { useQueries } from '@tanstack/solid-query'
|
||||
|
||||
function Posts(props: { ids: Array<number> }) {
|
||||
const combinedPostsQuery = useQueries(() => ({
|
||||
queries: props.ids.map((id) => ({
|
||||
queryKey: ['post', id],
|
||||
queryFn: () => fetchPost(id),
|
||||
})),
|
||||
combine: (postQueries) => {
|
||||
return {
|
||||
data: postQueries.map((postQuery) => postQuery.data),
|
||||
isPending: postQueries.some((postQuery) => postQuery.isPending),
|
||||
isError: postQueries.some((postQuery) => postQuery.isError),
|
||||
}
|
||||
},
|
||||
}))
|
||||
|
||||
return (
|
||||
<Switch
|
||||
fallback={
|
||||
<ul>
|
||||
<For each={combinedPostsQuery.data}>{(post) => <li>{post?.title}</li>}</For>
|
||||
</ul>
|
||||
}
|
||||
>
|
||||
<Match when={combinedPostsQuery.isPending}>Loading...</Match>
|
||||
<Match when={combinedPostsQuery.isError}>Error loading posts</Match>
|
||||
</Switch>
|
||||
)
|
||||
}
|
||||
```
|
||||
293
docs/framework/solid/reference/variables/createQuery.md
Normal file
293
docs/framework/solid/reference/variables/createQuery.md
Normal file
@@ -0,0 +1,293 @@
|
||||
---
|
||||
id: createQuery
|
||||
title: createQuery
|
||||
---
|
||||
|
||||
```ts
|
||||
const createQuery: {
|
||||
<TQueryFnData, TError, TData, TQueryKey> (options, queryClient?): UseQueryResult<TData, TError>;
|
||||
<TQueryFnData, TError, TData, TQueryKey> (options, queryClient?): DefinedUseQueryResult<TData, TError>;
|
||||
} = useQuery;
|
||||
```
|
||||
|
||||
Defined in: [packages/solid-query/src/index.ts:57](https://github.com/TanStack/query/blob/main/packages/solid-query/src/index.ts#L57)
|
||||
|
||||
## Call Signature
|
||||
|
||||
```ts
|
||||
<TQueryFnData, TError, TData, TQueryKey>(options, queryClient?): UseQueryResult<TData, TError>;
|
||||
```
|
||||
|
||||
### Type Parameters
|
||||
|
||||
#### TQueryFnData
|
||||
|
||||
`TQueryFnData` = `unknown`
|
||||
|
||||
#### TError
|
||||
|
||||
`TError` = `Error`
|
||||
|
||||
#### TData
|
||||
|
||||
`TData` = `TQueryFnData`
|
||||
|
||||
#### TQueryKey
|
||||
|
||||
`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
|
||||
|
||||
### Parameters
|
||||
|
||||
#### options
|
||||
|
||||
[`UndefinedInitialDataOptions`](../type-aliases/UndefinedInitialDataOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>
|
||||
|
||||
An accessor returning the [UndefinedInitialDataOptions](../type-aliases/UndefinedInitialDataOptions.md) to use — everything you can
|
||||
pass to `useQuery`.
|
||||
|
||||
#### queryClient?
|
||||
|
||||
() => [`QueryClient`](../classes/QueryClient.md)
|
||||
|
||||
An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
||||
will be used.
|
||||
|
||||
### Returns
|
||||
|
||||
[`UseQueryResult`](../type-aliases/UseQueryResult.md)\<`TData`, `TError`\>
|
||||
|
||||
The current query result, as a Solid store. `status` is `pending` if there is no cached data to
|
||||
display, `error` if the last fetch attempt failed, or `success` if the query has data to display.
|
||||
`isPending`/`isSuccess`/`isError` are derived booleans for convenience.
|
||||
|
||||
### See
|
||||
|
||||
[queryOptions](../functions/queryOptions.md) to share these options between `useQuery` and imperative APIs like `queryClient.query`.
|
||||
|
||||
### Examples
|
||||
|
||||
```tsx
|
||||
import { For, Match, Switch } from 'solid-js'
|
||||
import { useQuery } from '@tanstack/solid-query'
|
||||
|
||||
function Posts() {
|
||||
const postsQuery = useQuery(() => ({
|
||||
queryKey: ['posts'],
|
||||
queryFn: fetchPosts,
|
||||
}))
|
||||
|
||||
return (
|
||||
<Switch>
|
||||
<Match when={postsQuery.isPending}>Loading...</Match>
|
||||
<Match when={postsQuery.isError}>Error: {postsQuery.error.message}</Match>
|
||||
<Match when={postsQuery.isSuccess}>
|
||||
<ul>
|
||||
<For each={postsQuery.data}>{(post) => <li>{post.title}</li>}</For>
|
||||
</ul>
|
||||
<div>{postsQuery.isFetching ? 'Background Updating...' : ' '}</div>
|
||||
</Match>
|
||||
</Switch>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
`select` derives whatever `data` a component needs from the cached value, without changing what's
|
||||
actually stored in the cache — the cache still holds the full `Post[]`, but `data` here is a `number`:
|
||||
```tsx
|
||||
import { Match, Switch } from 'solid-js'
|
||||
import { useQuery } from '@tanstack/solid-query'
|
||||
|
||||
function PostCount() {
|
||||
const postsQuery = useQuery(() => ({
|
||||
queryKey: ['posts'],
|
||||
queryFn: fetchPosts,
|
||||
select: (posts) => posts.length,
|
||||
}))
|
||||
|
||||
return (
|
||||
<Switch>
|
||||
<Match when={postsQuery.isPending}>Loading...</Match>
|
||||
<Match when={postsQuery.isError}>Error: {postsQuery.error.message}</Match>
|
||||
<Match when={postsQuery.isSuccess}>{postsQuery.data} posts</Match>
|
||||
</Switch>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
A dependent query, only enabled once `postId` is set:
|
||||
```tsx
|
||||
import { Match, Switch } from 'solid-js'
|
||||
import { useQuery } from '@tanstack/solid-query'
|
||||
|
||||
function Post(props: { postId: number | undefined }) {
|
||||
const postQuery = useQuery(() => ({
|
||||
queryKey: ['post', props.postId],
|
||||
queryFn: () => fetchPost(props.postId!),
|
||||
enabled: props.postId != null,
|
||||
}))
|
||||
|
||||
return (
|
||||
<Switch fallback={<h1>{postQuery.data?.title}</h1>}>
|
||||
<Match when={props.postId == null}>Select a post</Match>
|
||||
<Match when={postQuery.isLoading}>Loading...</Match>
|
||||
<Match when={postQuery.isError}>Error: {postQuery.error.message}</Match>
|
||||
</Switch>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
The same dependent query, using `skipToken` to disable it in a type-safe way instead of relying on
|
||||
`enabled`. The non-null assertion is still needed — Solid's `props` narrowing doesn't survive into the
|
||||
`queryFn` closure the way a local `const` would — but `skipToken` keeps `queryFn`'s return type accurate
|
||||
without it. `refetch` doesn't work while `queryFn` is `skipToken` — use `enabled: false` instead if you
|
||||
need to trigger the query manually:
|
||||
```tsx
|
||||
import { Match, Switch } from 'solid-js'
|
||||
import { skipToken, useQuery } from '@tanstack/solid-query'
|
||||
|
||||
function Post(props: { postId: number | undefined }) {
|
||||
const postQuery = useQuery(() => ({
|
||||
queryKey: ['post', props.postId],
|
||||
queryFn: props.postId != null ? () => fetchPost(props.postId!) : skipToken,
|
||||
}))
|
||||
|
||||
return (
|
||||
<Switch fallback={<h1>{postQuery.data?.title}</h1>}>
|
||||
<Match when={props.postId == null}>Select a post</Match>
|
||||
<Match when={postQuery.isLoading}>Loading...</Match>
|
||||
<Match when={postQuery.isError}>Error: {postQuery.error.message}</Match>
|
||||
</Switch>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
Seeding a detail query from an already-cached list, to skip the loading state:
|
||||
```tsx
|
||||
import { useQuery, useQueryClient } from '@tanstack/solid-query'
|
||||
|
||||
function Post(props: { postId: number }) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const postQuery = useQuery(() => ({
|
||||
queryKey: ['post', props.postId],
|
||||
queryFn: () => fetchPost(props.postId),
|
||||
initialData: () =>
|
||||
queryClient
|
||||
.getQueryData<Array<Post>>(['posts'])
|
||||
?.find((post) => post.id === props.postId),
|
||||
}))
|
||||
|
||||
return postQuery.isError ? <span>Error: {postQuery.error.message}</span> : <h1>{postQuery.data?.title}</h1>
|
||||
}
|
||||
```
|
||||
|
||||
Paginated data, keeping the previous page's data visible while the next page loads:
|
||||
```tsx
|
||||
import { For, createSignal } from 'solid-js'
|
||||
import { keepPreviousData, useQuery } from '@tanstack/solid-query'
|
||||
|
||||
function Posts() {
|
||||
const [page, setPage] = createSignal(0)
|
||||
|
||||
const postsQuery = useQuery(() => ({
|
||||
queryKey: ['posts', page()],
|
||||
queryFn: () => fetchPosts(page()),
|
||||
placeholderData: keepPreviousData,
|
||||
}))
|
||||
|
||||
return (
|
||||
<div>
|
||||
<ul>
|
||||
<For each={postsQuery.data}>{(post) => <li>{post.title}</li>}</For>
|
||||
</ul>
|
||||
<button
|
||||
disabled={postsQuery.isPlaceholderData}
|
||||
onClick={() => setPage((old) => old + 1)}
|
||||
>
|
||||
Next Page
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
## Call Signature
|
||||
|
||||
```ts
|
||||
<TQueryFnData, TError, TData, TQueryKey>(options, queryClient?): DefinedUseQueryResult<TData, TError>;
|
||||
```
|
||||
|
||||
This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
|
||||
|
||||
### Type Parameters
|
||||
|
||||
#### TQueryFnData
|
||||
|
||||
`TQueryFnData` = `unknown`
|
||||
|
||||
#### TError
|
||||
|
||||
`TError` = `Error`
|
||||
|
||||
#### TData
|
||||
|
||||
`TData` = `TQueryFnData`
|
||||
|
||||
#### TQueryKey
|
||||
|
||||
`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
|
||||
|
||||
### Parameters
|
||||
|
||||
#### options
|
||||
|
||||
[`DefinedInitialDataOptions`](../type-aliases/DefinedInitialDataOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>
|
||||
|
||||
An accessor returning the [DefinedInitialDataOptions](../type-aliases/DefinedInitialDataOptions.md) to use — everything you can
|
||||
pass to `useQuery`, with `initialData` set.
|
||||
|
||||
#### queryClient?
|
||||
|
||||
() => [`QueryClient`](../classes/QueryClient.md)
|
||||
|
||||
An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
||||
will be used.
|
||||
|
||||
### Returns
|
||||
|
||||
[`DefinedUseQueryResult`](../type-aliases/DefinedUseQueryResult.md)\<`TData`, `TError`\>
|
||||
|
||||
The current query result, as a Solid store, typed so that `status` is `success` — or `error` if a
|
||||
fetch attempt fails while keeping the existing data (`status` never resolves to `pending` in this overload's
|
||||
type, since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for
|
||||
convenience.
|
||||
|
||||
### See
|
||||
|
||||
[queryOptions](../functions/queryOptions.md) to share these options between `useQuery` and imperative APIs like `queryClient.query`.
|
||||
|
||||
### Example
|
||||
|
||||
```tsx
|
||||
import { For } from 'solid-js'
|
||||
import { useQuery } from '@tanstack/solid-query'
|
||||
|
||||
function Posts() {
|
||||
// `postsQuery.data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the
|
||||
// list stays visible alongside the error.
|
||||
const postsQuery = useQuery(() => ({
|
||||
queryKey: ['posts'],
|
||||
queryFn: fetchPosts,
|
||||
initialData: [],
|
||||
}))
|
||||
|
||||
return (
|
||||
<div>
|
||||
{postsQuery.isError ? <span>Error: {postsQuery.error.message}</span> : null}
|
||||
<ul>
|
||||
<For each={postsQuery.data}>{(post) => <li>{post.title}</li>}</For>
|
||||
</ul>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
id: dataTagErrorSymbol
|
||||
title: dataTagErrorSymbol
|
||||
---
|
||||
|
||||
```ts
|
||||
const dataTagErrorSymbol: typeof dataTagErrorSymbol;
|
||||
```
|
||||
|
||||
Defined in: [packages/query-core/src/types.ts:63](https://github.com/TanStack/query/blob/main/packages/query-core/src/types.ts#L63)
|
||||
10
docs/framework/solid/reference/variables/dataTagSymbol.md
Normal file
10
docs/framework/solid/reference/variables/dataTagSymbol.md
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
id: dataTagSymbol
|
||||
title: dataTagSymbol
|
||||
---
|
||||
|
||||
```ts
|
||||
const dataTagSymbol: typeof dataTagSymbol;
|
||||
```
|
||||
|
||||
Defined in: [packages/query-core/src/types.ts:61](https://github.com/TanStack/query/blob/main/packages/query-core/src/types.ts#L61)
|
||||
13
docs/framework/solid/reference/variables/defaultScheduler.md
Normal file
13
docs/framework/solid/reference/variables/defaultScheduler.md
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
id: defaultScheduler
|
||||
title: defaultScheduler
|
||||
---
|
||||
|
||||
```ts
|
||||
const defaultScheduler: ScheduleFunction = systemSetTimeoutZero;
|
||||
```
|
||||
|
||||
Defined in: [packages/query-core/src/notifyManager.ts:19](https://github.com/TanStack/query/blob/main/packages/query-core/src/notifyManager.ts#L19)
|
||||
|
||||
Default scheduling function used by the notify manager.
|
||||
Schedules the callback with the system's `setTimeout(callback, 0)`.
|
||||
@@ -0,0 +1,59 @@
|
||||
---
|
||||
id: environmentManager
|
||||
title: environmentManager
|
||||
---
|
||||
|
||||
```ts
|
||||
const environmentManager: object;
|
||||
```
|
||||
|
||||
Defined in: [packages/query-core/src/environmentManager.ts:29](https://github.com/TanStack/query/blob/main/packages/query-core/src/environmentManager.ts#L29)
|
||||
|
||||
Manages how TanStack Query detects whether the current runtime should be treated as
|
||||
server-side, which disables scheduling refetch timers and changes the default `retry` count
|
||||
and `gcTime`. By default, the detection treats a missing `window` (or the presence of a
|
||||
`Deno` global) as server.
|
||||
|
||||
Override this for runtimes where that default detection would give the wrong answer — for
|
||||
example, a Service Worker, where `window` is undefined even though the environment should
|
||||
behave like a client.
|
||||
|
||||
## Type Declaration
|
||||
|
||||
### isServer()
|
||||
|
||||
```ts
|
||||
isServer: () => boolean;
|
||||
```
|
||||
|
||||
Returns whether the current runtime should be treated as a server environment.
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
|
||||
### setIsServer()
|
||||
|
||||
```ts
|
||||
setIsServer(isServerValue): void;
|
||||
```
|
||||
|
||||
Overrides the server check globally.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### isServerValue
|
||||
|
||||
`IsServerValue`
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { environmentManager } from '@tanstack/query-core'
|
||||
|
||||
environmentManager.setIsServer(() => false)
|
||||
```
|
||||
12
docs/framework/solid/reference/variables/focusManager.md
Normal file
12
docs/framework/solid/reference/variables/focusManager.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
id: focusManager
|
||||
title: focusManager
|
||||
---
|
||||
|
||||
```ts
|
||||
const focusManager: FocusManager;
|
||||
```
|
||||
|
||||
Defined in: [packages/query-core/src/focusManager.ts:142](https://github.com/TanStack/query/blob/main/packages/query-core/src/focusManager.ts#L142)
|
||||
|
||||
Singleton instance of [FocusManager](../interfaces/FocusManager.md), used to manage and observe the focus state within TanStack Query.
|
||||
14
docs/framework/solid/reference/variables/isServer.md
Normal file
14
docs/framework/solid/reference/variables/isServer.md
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
id: isServer
|
||||
title: isServer
|
||||
---
|
||||
|
||||
```ts
|
||||
const isServer: boolean;
|
||||
```
|
||||
|
||||
Defined in: [packages/query-core/src/utils.ts:114](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L114)
|
||||
|
||||
## Deprecated
|
||||
|
||||
use `environmentManager.isServer()` instead.
|
||||
166
docs/framework/solid/reference/variables/notifyManager.md
Normal file
166
docs/framework/solid/reference/variables/notifyManager.md
Normal file
@@ -0,0 +1,166 @@
|
||||
---
|
||||
id: notifyManager
|
||||
title: notifyManager
|
||||
---
|
||||
|
||||
```ts
|
||||
const notifyManager: object;
|
||||
```
|
||||
|
||||
Defined in: [packages/query-core/src/notifyManager.ts:144](https://github.com/TanStack/query/blob/main/packages/query-core/src/notifyManager.ts#L144)
|
||||
|
||||
Handles scheduling and batching callbacks in TanStack Query.
|
||||
|
||||
## Type Declaration
|
||||
|
||||
### batch()
|
||||
|
||||
```ts
|
||||
readonly batch: <T>(callback) => T;
|
||||
```
|
||||
|
||||
Batches all updates scheduled inside the passed callback.
|
||||
This is mainly used internally to optimize query client updating.
|
||||
Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
|
||||
The return value of `callback` is passed through.
|
||||
|
||||
#### Type Parameters
|
||||
|
||||
##### T
|
||||
|
||||
`T`
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### callback
|
||||
|
||||
() => `T`
|
||||
|
||||
#### Returns
|
||||
|
||||
`T`
|
||||
|
||||
### batchCalls()
|
||||
|
||||
```ts
|
||||
readonly batchCalls: <T>(callback) => BatchCallsCallback<T>;
|
||||
```
|
||||
|
||||
All calls to the wrapped function will be batched.
|
||||
|
||||
#### Type Parameters
|
||||
|
||||
##### T
|
||||
|
||||
`T` *extends* `unknown`[]
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### callback
|
||||
|
||||
`BatchCallsCallback`\<`T`\>
|
||||
|
||||
#### Returns
|
||||
|
||||
`BatchCallsCallback`\<`T`\>
|
||||
|
||||
### schedule()
|
||||
|
||||
```ts
|
||||
schedule: (callback) => void;
|
||||
```
|
||||
|
||||
Schedules a function to be run on the next batch.
|
||||
By default, the batch is run with a `setTimeout`, but this can be configured via `setScheduler`.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### callback
|
||||
|
||||
`NotifyCallback`
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
### setBatchNotifyFunction()
|
||||
|
||||
```ts
|
||||
readonly setBatchNotifyFunction: (fn) => void;
|
||||
```
|
||||
|
||||
Use this method to set a custom function to batch notifications together into a single tick.
|
||||
Framework adapters use this to plug in their own batching primitive, so that a single query
|
||||
update only triggers one re-render instead of one per subscriber.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### fn
|
||||
|
||||
`BatchNotifyFunction`
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
import { notifyManager } from '@tanstack/query-core'
|
||||
import { batch } from 'solid-js'
|
||||
|
||||
notifyManager.setBatchNotifyFunction(batch)
|
||||
```
|
||||
|
||||
### setNotifyFunction()
|
||||
|
||||
```ts
|
||||
readonly setNotifyFunction: (fn) => void;
|
||||
```
|
||||
|
||||
Use this method to set a custom notify function.
|
||||
This can be used to for example wrap notifications with `React.act` while running tests.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### fn
|
||||
|
||||
`NotifyFunction`
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
### setScheduler()
|
||||
|
||||
```ts
|
||||
readonly setScheduler: (fn) => void;
|
||||
```
|
||||
|
||||
Configures a custom callback that schedules when the next batch runs.
|
||||
The default behavior is `setTimeout(callback, 0)`.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### fn
|
||||
|
||||
`ScheduleFunction`
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
import { notifyManager } from '@tanstack/query-core'
|
||||
|
||||
// Schedule batches in the next microtask
|
||||
notifyManager.setScheduler(queueMicrotask)
|
||||
|
||||
// Schedule batches before the next frame is rendered
|
||||
notifyManager.setScheduler(requestAnimationFrame)
|
||||
|
||||
// Schedule batches some time in the future
|
||||
notifyManager.setScheduler((cb) => setTimeout(cb, 10))
|
||||
```
|
||||
12
docs/framework/solid/reference/variables/onlineManager.md
Normal file
12
docs/framework/solid/reference/variables/onlineManager.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
id: onlineManager
|
||||
title: onlineManager
|
||||
---
|
||||
|
||||
```ts
|
||||
const onlineManager: OnlineManager;
|
||||
```
|
||||
|
||||
Defined in: [packages/query-core/src/onlineManager.ts:117](https://github.com/TanStack/query/blob/main/packages/query-core/src/onlineManager.ts#L117)
|
||||
|
||||
Singleton instance of [OnlineManager](../interfaces/OnlineManager.md), used to manage and observe the online state within TanStack Query.
|
||||
23
docs/framework/solid/reference/variables/skipToken.md
Normal file
23
docs/framework/solid/reference/variables/skipToken.md
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
id: skipToken
|
||||
title: skipToken
|
||||
---
|
||||
|
||||
```ts
|
||||
const skipToken: typeof skipToken;
|
||||
```
|
||||
|
||||
Defined in: [packages/query-core/src/utils.ts:522](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L522)
|
||||
|
||||
Sentinel value that can be passed as a query's `queryFn` to conditionally disable the query (equivalent
|
||||
to `enabled: false`) while preserving full type inference for the query's data. Unlike `enabled: false`,
|
||||
a query disabled via `skipToken` cannot be triggered with `refetch`.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
new QueryObserver(queryClient, {
|
||||
queryKey: ['post', postId],
|
||||
queryFn: postId != null ? () => fetchPost(postId) : skipToken,
|
||||
})
|
||||
```
|
||||
12
docs/framework/solid/reference/variables/timeoutManager.md
Normal file
12
docs/framework/solid/reference/variables/timeoutManager.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
id: timeoutManager
|
||||
title: timeoutManager
|
||||
---
|
||||
|
||||
```ts
|
||||
const timeoutManager: TimeoutManager;
|
||||
```
|
||||
|
||||
Defined in: [packages/query-core/src/timeoutManager.ts:232](https://github.com/TanStack/query/blob/main/packages/query-core/src/timeoutManager.ts#L232)
|
||||
|
||||
Singleton instance of [TimeoutManager](../interfaces/TimeoutManager.md), used throughout TanStack Query to schedule and cancel timers.
|
||||
10
docs/framework/solid/reference/variables/unsetMarker.md
Normal file
10
docs/framework/solid/reference/variables/unsetMarker.md
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
id: unsetMarker
|
||||
title: unsetMarker
|
||||
---
|
||||
|
||||
```ts
|
||||
const unsetMarker: typeof unsetMarker;
|
||||
```
|
||||
|
||||
Defined in: [packages/query-core/src/types.ts:65](https://github.com/TanStack/query/blob/main/packages/query-core/src/types.ts#L65)
|
||||
Reference in New Issue
Block a user