Open History to see the last commit
1<script lang="ts">
2 import { sleep } from '@tanstack/query-test-utils'
3 import { createMutation, setQueryClientContext } from '../../src/index.js'
4 import type { QueryClient } from '@tanstack/query-core'
5β
6 type Props = {
7 queryClient: QueryClient
8 onSuccessMock: (data: number) => void
9 onSettledMock: (data: number | undefined) => void
10 }
11β
12 let { queryClient, onSettledMock, onSuccessMock }: Props = $props()
13β
14 let count = $state(0)
15β
16 setQueryClientContext(queryClient)
17β
18 const mutation = createMutation(() => ({
19 mutationFn: (vars: { count: number }) => sleep(10).then(() => vars.count),
20 onSuccess: (data) => {
21 onSuccessMock(data)
22 },
23 onSettled: (data) => {
24 onSettledMock(data)
25 },
26 }))
27</script>
28β
29<button onclick={() => mutation.mutate({ count: ++count })}>Mutate</button>
30β
31<div>Count: {count}</div>