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

MutationFnContext.svelte

23 lines650 Bytes

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>