Open History to see the last commit
1<script lang="ts">
2 import type { MutationKey, 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 mutationKey?: MutationKey
9 onSuccessMock: (...args: Array<unknown>) => void
10 }
11β
12 const { queryClient, mutationKey, onSuccessMock }: Props = $props()
13β
14 setQueryClientContext(queryClient)
15β
16 const mutation = createMutation(() => ({
17 mutationKey,
18 mutationFn: (text: string) => sleep(10).then(() => text.toUpperCase()),
19 onMutate: (text: string) => ({ startedWith: text }),
20 onSuccess: onSuccessMock,
21 }))
22</script>
23β
24<button onclick={() => mutation.mutate('todo')}>Mutate</button>