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 { QueryClient, QueryKey } from '@tanstack/query-core'
5β
6 type Props = {
7 queryClient: QueryClient
8 queryKey: QueryKey
9 }
10β
11 let { queryClient, queryKey }: Props = $props()
12β
13 setQueryClientContext(queryClient)
14β
15 const mutation = createMutation(() => ({
16 mutationFn: (_text: string, context) =>
17 sleep(10).then(() => context.client.getQueryData(queryKey)),
18 }))
19</script>
20β
21<button onclick={() => mutation.mutate('todo')}>Mutate</button>
22β
23<div>data: {mutation.data}</div>