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: () => sleep(10).then(() => 'mutated'),
17 onSuccess: (_data, _variables, _onMutateResult, context) => {
18 context.client.invalidateQueries({ queryKey })
19 },
20 }))
21</script>
22β
23<button onclick={() => mutation.mutate()}>Mutate</button>