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

PerCallSuccess.svelte

30 lines766 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 onclick={() => mutation.mutate('todo', { onSuccess: onSuccessMutate })}>
29 Mutate
30</button>