Skip to content

Commit 85b8ea6

Browse files
committed
feat: cancel method for Query
1 parent be10f62 commit 85b8ea6

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

.changeset/chubby-years-drive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"mobx-tanstack-query": minor
3+
---
4+
5+
`cancel()` method for `Query` (-> `queryClient.cancelQueries`)

src/query.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
QueryObserverBaseResult,
1111
FetchStatus,
1212
QueryStatus,
13+
CancelOptions,
14+
ResetOptions,
1315
} from '@tanstack/query-core';
1416
import { LinkedAbortController } from 'linked-abort-controller';
1517
import {
@@ -575,12 +577,25 @@ export class Query<
575577
}
576578
}
577579

578-
async reset(params?: QueryResetParams) {
579-
return await this.queryClient.resetQueries({
580-
queryKey: this.options.queryKey,
581-
exact: true,
582-
...params,
583-
} as any);
580+
async reset(params?: QueryResetParams, options?: ResetOptions) {
581+
return await this.queryClient.resetQueries(
582+
{
583+
queryKey: this.options.queryKey,
584+
exact: true,
585+
...params,
586+
},
587+
options,
588+
);
589+
}
590+
591+
async cancel(options?: CancelOptions) {
592+
return await this.queryClient.cancelQueries(
593+
{
594+
queryKey: this.options.queryKey,
595+
exact: true,
596+
},
597+
options,
598+
);
584599
}
585600

586601
async invalidate(params?: QueryInvalidateParams) {

0 commit comments

Comments
 (0)