Open History to see the last commit
1import { mutationOptions, queryOptions } from '@tanstack/react-query'
2import { todosAPI } from './api'
3β
4export const todosQueries = {
5 all: () => ['todos'] as const,
6 lists: () => [...todosQueries.all(), 'list'] as const,
7 list: (filter: string) =>
8 queryOptions({
9 queryKey: [...todosQueries.lists(), { filter }] as const,
10 queryFn: ({ signal }) => todosAPI.getTodos({ filter, signal }),
11 }),
12 detail: (id: number) =>
13 queryOptions({
14 queryKey: [...todosQueries.all(), 'detail', id] as const,
15 queryFn: () => todosAPI.getTodo({ id }),
16 }),
17}
18β
19export const todosMutations = {
20 create: () =>
21 mutationOptions({
22 mutationFn: todosAPI.createTodo,
23 }),
24 update: () =>
25 mutationOptions({
26 mutationFn: todosAPI.updateTodo,
27 }),
28}