@@ -260,6 +260,7 @@ console.log(query.fetchStatus); // "paused" when query is paused
260260```
261261
262262Explanation of difference between ` fetchStatus ` and ` status ` :
263+
263264- ` status ` indicates the overall result state of the query: "pending", "error", or "success"
264265- ` fetchStatus ` indicates the current fetching state of the query: "fetching", "paused", or "idle"
265266- A query can be in "fetching" state while still having a "pending" status, or it can be in "idle" state while having an "error" or "success" status
@@ -275,7 +276,7 @@ The underlying query observer instance.
275276#### ` isResultRequsted: boolean ` <Badge type =" info " text =" observable.ref " />
276277
277278Any time when you trying to get access to ` result ` property this field sets as ` true `
278- This field is needed for ` enableOnDemand ` option
279+ This field is needed for ` enableOnDemand ` option
279280
280281#### ` result: QueryObserverResult<TData, TError> `
281282
@@ -296,13 +297,13 @@ const query = new Query(queryClient, () => ({
296297// Update data with a function
297298query .setData ((oldData ) => ({
298299 ... oldData ,
299- name: " Fluffy"
300+ name: " Fluffy" ,
300301}));
301302
302303// Update data with a new value
303304query .setData ({
304305 id: 1 ,
305- name: " Fluffy"
306+ name: " Fluffy" ,
306307});
307308```
308309
@@ -321,7 +322,7 @@ const query = new Query(queryClient, () => ({
321322// Update query options
322323query .update ({
323324 enabled: false ,
324- staleTime: 10000
325+ staleTime: 10000 ,
325326});
326327```
327328
@@ -342,7 +343,7 @@ const result = await query.refetch();
342343console .log (result .data );
343344```
344345
345- #### ` reset(params?: QueryResetParams): Promise<void> `
346+ #### ` reset(params?: QueryResetParams, options?: ResetOptions ): Promise<void> `
346347
347348Reset current query (Uses [ queryClient.resetQueries] ( https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientresetqueries ) )
348349
@@ -374,6 +375,25 @@ const query = new Query(queryClient, () => ({
374375await query .invalidate ();
375376```
376377
378+ #### ` cancel(options?: CancelOptions): Promise<void> `
379+
380+ Cancel current query (Uses [ queryClient.cancelQueries] ( https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientcancelqueries ) )
381+
382+ Example:
383+
384+ ``` ts{3,7}
385+ const query = new Query(queryClient, () => ({
386+ queryKey: ["pets"],
387+ queryFn: async ({ signal }) => api.fetchPets({ signal }),
388+ }));
389+
390+ // Cancel the query
391+ await query.cancel();
392+ ```
393+
394+ ::: tip do not forget to pass abort signal to your api call function
395+ :::
396+
377397#### ` onDone(doneListener: QueryDoneListener<TData>): void `
378398
379399Subscribe when query has been successfully fetched data
@@ -388,7 +408,7 @@ const query = new Query(queryClient, () => ({
388408
389409// Subscribe to successful fetch
390410query .onDone ((data ) => {
391- console .log (' Query completed successfully:' , data );
411+ console .log (" Query completed successfully:" , data );
392412});
393413```
394414
@@ -406,7 +426,7 @@ const query = new Query(queryClient, () => ({
406426
407427// Subscribe to fetch errors
408428query .onError ((error ) => {
409- console .log (' Query failed:' , error );
429+ console .log (" Query failed:" , error );
410430});
411431```
412432
@@ -454,7 +474,6 @@ const query = new Query(queryClient, () => ({
454474query .destroy ();
455475```
456476
457-
458477## Recommendations
459478
460479### Don't forget about ` abortSignal ` s or ` lazy ` option
0 commit comments