Open History to see the last commit
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 MutationKey,
7 QueryClient,
8 } from '@tanstack/query-core'
9β
10 type Props = {
11 queryClient: QueryClient
12 mutationKey?: MutationKey
13 onSuccessMock: (
14 data: string,
15 variables: string,
16 onMutateResult: { startedWith: string },
17 context: MutationFunctionContext,
18 ) => void
19 }
20β
21 let { queryClient, mutationKey, onSuccessMock }: Props = $props()
22β
23 setQueryClientContext(queryClient)
24β
25 const mutation = createMutation(() => ({
26 mutationKey,
27 mutationFn: (text: string) => sleep(10).then(() => text.toUpperCase()),
28 onMutate: (text: string) => ({ startedWith: text }),
29 onSuccess: onSuccessMock,
30 }))
31</script>
32β
33<button onclick={() => mutation.mutate('todo')}>Mutate</button>