aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/src/apis/queries/hooks.ts
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/apis/queries/hooks.ts')
-rw-r--r--frontend/src/apis/queries/hooks.ts40
1 files changed, 20 insertions, 20 deletions
diff --git a/frontend/src/apis/queries/hooks.ts b/frontend/src/apis/queries/hooks.ts
index 5f9bf63d3..2f17b5efe 100644
--- a/frontend/src/apis/queries/hooks.ts
+++ b/frontend/src/apis/queries/hooks.ts
@@ -1,12 +1,12 @@
-import { GetItemId, useOnValueChange } from "@/utilities";
-import { usePageSize } from "@/utilities/storage";
import { useCallback, useEffect, useState } from "react";
import {
QueryKey,
- UseQueryResult,
useQuery,
useQueryClient,
-} from "react-query";
+ UseQueryResult,
+} from "@tanstack/react-query";
+import { GetItemId, useOnValueChange } from "@/utilities";
+import { usePageSize } from "@/utilities/storage";
import { QueryKeys } from "./keys";
export type UsePaginationQueryResult<T extends object> = UseQueryResult<
@@ -39,31 +39,31 @@ export function usePaginationQuery<
const start = page * pageSize;
- const results = useQuery(
- [...queryKey, QueryKeys.Range, { start, size: pageSize }],
- () => {
+ const results = useQuery({
+ queryKey: [...queryKey, QueryKeys.Range, { start, size: pageSize }],
+
+ queryFn: () => {
const param: Parameter.Range = {
start,
length: pageSize,
};
return queryFn(param);
},
- {
- onSuccess: ({ data }) => {
- if (cacheIndividual) {
- data.forEach((item) => {
- const id = GetItemId(item);
- if (id) {
- client.setQueryData([...queryKey, id], item);
- }
- });
- }
- },
- },
- );
+ });
const { data } = results;
+ useEffect(() => {
+ if (results.isSuccess && results.data && cacheIndividual) {
+ results.data.data.forEach((item) => {
+ const id = GetItemId(item);
+ if (id) {
+ client.setQueryData([...queryKey, id], item);
+ }
+ });
+ }
+ }, [results.isSuccess, results.data, client, cacheIndividual, queryKey]);
+
const totalCount = data?.total ?? 0;
const pageCount = Math.ceil(totalCount / pageSize);