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

ConcurrentMutate.svelte

38 lines948 Bytes

1<script lang="ts">
2 import { sleep } from '@tanstack/query-test-utils'
3 import { createMutation, setQueryClientContext } from '../../src/index.js'
4 import type {
5 MutationFunctionContext,
6 QueryClient,
7 } from '@tanstack/query-core'
8​
9 type Props = {
10 queryClient: QueryClient
11 onSuccessMutate: (
12 data: string,
13 variables: string,
14 onMutateResult: unknown,
15 context: MutationFunctionContext,
16 ) => void
17 }
18​
19 let { queryClient, onSuccessMutate }: Props = $props()
20​
21 setQueryClientContext(queryClient)
22​
23 const mutation = createMutation(() => ({
24 mutationFn: (text: string) => sleep(10).then(() => text),
25 }))
26</script>
27​
28<button
29 onclick={() => mutation.mutate('Todo 1', { onSuccess: onSuccessMutate })}
31 mutate1
32</button>
33<button
34 onclick={() => mutation.mutate('Todo 2', { onSuccess: onSuccessMutate })}
36 mutate2
37</button>
38<div>data: {mutation.data ?? 'null'}, status: {mutation.status}</div>