Open History to see the last commit
1<script lang="ts">
2 import type { QueryClient } from '@tanstack/query-core'
3 import { createMutation, setQueryClientContext } from '../../src/index.js'
4 import { sleep } from '@tanstack/query-test-utils'
5β
6 type Props = {
7 queryClient: QueryClient
8 onSuccessMutate: (...args: Array<unknown>) => void
9 }
10β
11 const { queryClient, onSuccessMutate }: Props = $props()
12β
13 setQueryClientContext(queryClient)
14β
15 const mutation = createMutation(() => ({
16 mutationFn: (text: string) => sleep(10).then(() => text),
17 }))
18</script>
19β
20<button
21 onclick={() => mutation.mutate('Todo 1', { onSuccess: onSuccessMutate })}
22>
23 mutate1
24</button>
25<button
26 onclick={() => mutation.mutate('Todo 2', { onSuccess: onSuccessMutate })}
27>
28 mutate2
29</button>
30<div>data: {mutation.data ?? 'null'}, status: {mutation.status}</div>