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

Base.svelte

25 lines688 Bytes

1<script lang="ts">
2 import { createKey, sleep } from '@tanstack/query-test-utils'
3 import { setQueryClientContext } from '../../src/context.js'
4 import { createMutation, useIsMutating } from '../../src/index.js'
5 import type { QueryClient } from '@tanstack/query-core'
6​
7 type Props = {
8 queryClient: QueryClient
9 }
10​
11 let { queryClient }: Props = $props()
12​
13 setQueryClientContext(queryClient)
14​
15 const mutation = createMutation(() => ({
16 mutationKey: createKey(),
17 mutationFn: () => sleep(10).then(() => 'data'),
18 }))
19​
20 const isMutating = useIsMutating()
21</script>
22​
23<button onclick={() => mutation.mutate()}>Trigger</button>
24​
25<div>isMutating: {isMutating.current}</div>