Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

queries.tsx

23 lines694 Bytes

1import { queryOptions } from '@tanstack/react-query'
2​
3// βœ… passes: queryKey and queryFn are co-located via queryOptions()
4export const todosOptions = queryOptions({
5 queryKey: ['todos'],
6 queryFn: () => fetchTodos(),
7})
8​
9// βœ… passes: factory function wrapping queryOptions()
10export const todoOptions = (id: string) =>
11 queryOptions({
12 queryKey: ['todo', id],
13 queryFn: () => fetchTodo(id),
14 })
15​
16function fetchTodos(): Promise<Array<{ id: string; title: string }>> {
17 throw new Error('not implemented')
19​
20// eslint-disable-next-line @typescript-eslint/no-unused-vars
21function fetchTodo(id: string): Promise<{ id: string; title: string }> {
22 throw new Error('not implemented')