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

PerCallSuccess.svelte

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