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

ConcurrentMutate.svelte

30 lines816 Bytes

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 })}
23 mutate1
24</button>
25<button
26 onclick={() => mutation.mutate('Todo 2', { onSuccess: onSuccessMutate })}
28 mutate2
29</button>
30<div>data: {mutation.data ?? 'null'}, status: {mutation.status}</div>