24 lines
652 B
Svelte
24 lines
652 B
Svelte
<script lang="ts">
|
|
import type { QueryClient, QueryKey } from '@tanstack/query-core'
|
|
import { createMutation, setQueryClientContext } from '../../src/index.js'
|
|
import { sleep } from '@tanstack/query-test-utils'
|
|
|
|
type Props = {
|
|
queryClient: QueryClient
|
|
queryKey: QueryKey
|
|
}
|
|
|
|
const { queryClient, queryKey }: Props = $props()
|
|
|
|
setQueryClientContext(queryClient)
|
|
|
|
const mutation = createMutation(() => ({
|
|
mutationFn: (_text: string, context) =>
|
|
sleep(10).then(() => context.client.getQueryData(queryKey)),
|
|
}))
|
|
</script>
|
|
|
|
<button onclick={() => mutation.mutate('todo')}>Mutate</button>
|
|
|
|
<div>data: {mutation.data}</div>
|