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: 1 addition & 46 deletions docs/framework/preact/reference/functions/useInfiniteQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ function Projects() {
function useInfiniteQuery<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options, queryClient?): UseInfiniteQueryResult<TData, TError>;
```

Defined in: [preact-query/src/useInfiniteQuery.ts:390](https://github.com/TanStack/query/blob/main/packages/preact-query/src/useInfiniteQuery.ts#L390)
Defined in: [preact-query/src/useInfiniteQuery.ts:344](https://github.com/TanStack/query/blob/main/packages/preact-query/src/useInfiniteQuery.ts#L344)

The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of `queryFn`,
`initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
Expand Down Expand Up @@ -416,51 +416,6 @@ function Projects() {
}
```

Warming the cache on hover, so `<Comments>` has data as soon as it's clicked. Requires an
[infiniteQueryOptions](infiniteQueryOptions.md) factory, so the hook and the imperative call share the same cache entry:
```tsx
import {
infiniteQueryOptions,
noop,
useInfiniteQuery,
useQueryClient,
} from '@tanstack/preact-query'

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

function Comments({ postId }: { postId: string }) {
const { data, isPending, isError, error } = useInfiniteQuery(commentsOptions(postId))

if (isPending) return 'Loading...'
if (isError) return <span>Error: {error.message}</span>

return (
<ul>
{data.pages.map((page) => page.comments.map((c) => <li key={c.id}>{c.text}</li>))}
</ul>
)
}

function PostLink({ postId, title }: { postId: string; title: string }) {
const queryClient = useQueryClient()

return (
<a
href={`/posts/${postId}`}
onMouseEnter={() => queryClient.infiniteQuery(commentsOptions(postId)).catch(noop)}
>
{title}
</a>
)
}
```

A query that's disabled, type safe, until `postId` is set — pass `skipToken` as `queryFn`
instead of setting `enabled: false`:
```tsx
Expand Down
33 changes: 1 addition & 32 deletions docs/framework/preact/reference/functions/useQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function Posts() {
function useQuery<TQueryFnData, TError, TData, TQueryKey>(options, queryClient?): UseQueryResult<TData, TError>;
```

Defined in: [preact-query/src/useQuery.ts:293](https://github.com/TanStack/query/blob/main/packages/preact-query/src/useQuery.ts#L293)
Defined in: [preact-query/src/useQuery.ts:261](https://github.com/TanStack/query/blob/main/packages/preact-query/src/useQuery.ts#L261)

### Type Parameters

Expand Down Expand Up @@ -358,34 +358,3 @@ function Posts() {
)
}
```

Warming the cache on hover, so `<Post>` has data as soon as it's clicked. Requires a
[queryOptions](queryOptions.md) factory, so the hook and the imperative call share the same cache entry:
```tsx
import { noop, queryOptions, useQuery, useQueryClient } from '@tanstack/preact-query'

const postOptions = (id: string) =>
queryOptions({
queryKey: ['post', id],
queryFn: () => fetchPost(id),
})

function Post({ id }: { id: string }) {
const { data, isError, error } = useQuery(postOptions(id))
if (isError) return <span>Error: {error.message}</span>
return <h1>{data?.title}</h1>
}

function PostLink({ id, title }: { id: string; title: string }) {
const queryClient = useQueryClient()

return (
<a
href={`/posts/${id}`}
onMouseEnter={() => queryClient.query(postOptions(id)).catch(noop)}
>
{title}
</a>
)
}
```
46 changes: 0 additions & 46 deletions packages/preact-query/src/useInfiniteQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,52 +312,6 @@ export function useInfiniteQuery<
* ```
*
* @example
* Warming the cache on hover, so `<Comments>` has data as soon as it's clicked. Requires an
* {@link infiniteQueryOptions} factory, so the hook and the imperative call share the same cache entry:
* ```tsx
* import {
* infiniteQueryOptions,
* noop,
* useInfiniteQuery,
* useQueryClient,
* } from '@tanstack/preact-query'
*
* const commentsOptions = (postId: string) =>
* infiniteQueryOptions({
* queryKey: ['post', postId, 'comments'],
* queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
* initialPageParam: 0,
* getNextPageParam: (lastPage) => lastPage.nextId,
* })
*
* function Comments({ postId }: { postId: string }) {
* const { data, isPending, isError, error } = useInfiniteQuery(commentsOptions(postId))
*
* if (isPending) return 'Loading...'
* if (isError) return <span>Error: {error.message}</span>
*
* return (
* <ul>
* {data.pages.map((page) => page.comments.map((c) => <li key={c.id}>{c.text}</li>))}
* </ul>
* )
* }
*
* function PostLink({ postId, title }: { postId: string; title: string }) {
* const queryClient = useQueryClient()
*
* return (
* <a
* href={`/posts/${postId}`}
* onMouseEnter={() => queryClient.infiniteQuery(commentsOptions(postId)).catch(noop)}
* >
* {title}
* </a>
* )
* }
* ```
*
* @example
* A query that's disabled, type safe, until `postId` is set — pass `skipToken` as `queryFn`
* instead of setting `enabled: false`:
* ```tsx
Expand Down
32 changes: 0 additions & 32 deletions packages/preact-query/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,38 +257,6 @@ export function useQuery<
* )
* }
* ```
*
* @example
* Warming the cache on hover, so `<Post>` has data as soon as it's clicked. Requires a
* {@link queryOptions} factory, so the hook and the imperative call share the same cache entry:
* ```tsx
* import { noop, queryOptions, useQuery, useQueryClient } from '@tanstack/preact-query'
*
* const postOptions = (id: string) =>
* queryOptions({
* queryKey: ['post', id],
* queryFn: () => fetchPost(id),
* })
*
* function Post({ id }: { id: string }) {
* const { data, isError, error } = useQuery(postOptions(id))
* if (isError) return <span>Error: {error.message}</span>
* return <h1>{data?.title}</h1>
* }
*
* function PostLink({ id, title }: { id: string; title: string }) {
* const queryClient = useQueryClient()
*
* return (
* <a
* href={`/posts/${id}`}
* onMouseEnter={() => queryClient.query(postOptions(id)).catch(noop)}
* >
* {title}
* </a>
* )
* }
* ```
*/
export function useQuery<
TQueryFnData = unknown,
Expand Down
Loading