Skip to content

Commit 79be592

Browse files
update reactQuery version
1 parent 3828003 commit 79be592

File tree

8 files changed

+1001
-806
lines changed

8 files changed

+1001
-806
lines changed

package-lock.json

Lines changed: 342 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
"@fortawesome/free-regular-svg-icons": "^6.6.0",
1515
"@fortawesome/free-solid-svg-icons": "^6.6.0",
1616
"@fortawesome/react-fontawesome": "^0.2.2",
17+
"@tanstack/react-query": "^5.74.4",
1718
"axios": "^1.7.8",
1819
"i18next": "^24.0.5",
1920
"next": "14.2.3",
2021
"react": "^18",
2122
"react-dom": "^18",
2223
"react-hot-toast": "^2.4.1",
2324
"react-i18next": "^15.1.4",
24-
"react-query": "^3.39.3",
2525
"sass": "^1.76.0",
2626
"scss": "^0.2.4",
2727
"swiper": "^11.1.1",

src/component/productDetails/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { FC } from "react";
2-
import { useQuery } from "react-query";
2+
import { useQuery } from "@tanstack/react-query";
33

44
import { FeaturedProductAPI } from "@/const/endPoint";
55
import { FeaturedProductTransformer } from "@/utils/api/transformer/featuredProduct";

src/const/queryClient.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { QueryClient } from "react-query";
1+
import { QueryClient } from "@tanstack/react-query";
22

33
export const queryClient = new QueryClient({
44
defaultOptions: {
55
queries: {
66
staleTime: 5 * 60 * 1000,
7-
cacheTime: 30 * 60 * 1000,
87
retry: 3,
98
retryDelay: (attempt: any) => Math.min(1000 * 2 ** attempt, 30000),
109
refetchOnWindowFocus: true,

src/pages/category/[slug].tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { useRouter } from "next/router";
1212
import Placeholder from "@/component/category/placeholder";
1313
import { CategoryTransformer } from "@/utils/api/transformer/category";
1414
import { useMegaMenu } from "@/context/menuContext";
15-
import { useQuery } from "react-query";
15+
import { useQuery } from "@tanstack/react-query";
1616
import MetaTags from "@/component/metaTags";
1717

1818
const fetchCategoryData = async (
@@ -37,15 +37,13 @@ const CategoryPage: FC<CategoryPageProps> = ({ initialCategory }) => {
3737
const menu = useMegaMenu();
3838
const page = parseInt(router.query.page as string, 10) || 0;
3939
const categoryId = String(router.query.slug);
40-
const { data: category, isLoading } = useQuery<Category>(
41-
["categoryData", categoryId, page, filterQuery, orderQuery],
42-
() => fetchCategoryData(categoryId, page, filterQuery, orderQuery),
43-
{
44-
initialData: initialCategory || undefined,
45-
enabled: !initialCategory,
46-
refetchOnMount: false,
47-
}
48-
);
40+
const { data: category, isLoading } = useQuery<Category>({
41+
queryKey: ["categoryData", categoryId, page, filterQuery, orderQuery],
42+
queryFn: () => fetchCategoryData(categoryId, page, filterQuery, orderQuery),
43+
initialData: initialCategory || undefined,
44+
enabled: !initialCategory,
45+
refetchOnMount: false,
46+
});
4947

5048
if (isLoading) {
5149
return <Placeholder />;

src/pages/index.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { MegaMenuProvider } from "@/context/menuContext";
99
import { HomeTransformer } from "@/utils/api/transformer/home";
1010
import { getData } from "@/utils/api/fetchData/apiCall";
1111
import { useScrollRestoration } from "@/utils/hooks";
12-
import { useQuery } from "react-query";
12+
import { useQuery } from "@tanstack/react-query";
1313
import { useRouter } from "next/router";
1414
import { GetServerSidePropsContext } from "next";
1515
import MetaTags from "@/component/metaTags";
@@ -26,16 +26,13 @@ export default function Home({
2626
useScrollRestoration();
2727
const router = useRouter();
2828
const locale = router.locale || "en";
29-
const { data: carouselData } = useQuery<Product[]>(
30-
["homePage"],
31-
() => fetchCHomeData(),
32-
33-
{
34-
initialData: homeProductCarousel || undefined,
35-
enabled: !homeProductCarousel,
36-
refetchOnMount: false,
37-
}
38-
);
29+
const { data: carouselData } = useQuery<Product[]>({
30+
queryKey: ["homePage"],
31+
queryFn: () => fetchCHomeData(),
32+
initialData: homeProductCarousel || undefined,
33+
enabled: !homeProductCarousel,
34+
refetchOnMount: false,
35+
});
3936

4037
return (
4138
<>

src/utils/hooks/api/useFetchProductData.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useQuery } from "react-query";
1+
import { useQuery } from "@tanstack/react-query";
22
import { getData } from "@/utils/api/fetchData/apiCall";
33
import { ProductTransformer } from "@/utils/api/transformer/product";
44
import { ProductDetailAPI } from "@/const/endPoint";
@@ -43,18 +43,16 @@ export const useFetchProductData = ({
4343
refresh?: boolean;
4444
initialProduct?: any;
4545
}) => {
46-
return useQuery(
47-
["productData", productId, selectedOption],
48-
() =>
46+
return useQuery({
47+
queryKey: ["productData", productId, selectedOption],
48+
queryFn: () =>
4949
fetchProductData({
5050
productId,
5151
selectedOption,
5252
refresh,
5353
}),
54-
{
55-
initialData: initialProduct || undefined,
56-
enabled: !initialProduct,
57-
refetchOnMount: false,
58-
}
59-
);
54+
initialData: initialProduct || undefined,
55+
enabled: !initialProduct,
56+
refetchOnMount: false,
57+
});
6058
};

0 commit comments

Comments
 (0)