tuyetnhi1607 1 жил өмнө
parent
commit
4a269fbda5
1 өөрчлөгдсөн 8 нэмэгдсэн , 7 устгасан
  1. 8 7
      src/pages/Explore.tsx

+ 8 - 7
src/pages/Explore.tsx

@@ -7,22 +7,23 @@ import { useDispatch, useSelector } from "react-redux";
 import {
   fetchExploreHome,
   fetchExploreSearch,
-  resetExploreHome
+  resetExploreHome,
 } from "@src/store/reducers/ExploreReducer";
 import useExploreFilter from "@src/hooks/useExploreFilter";
 import { useCallbackAwaitStateSync } from "use-callback-await-state-sync";
 import useMore from "@src/hooks/useMore";
 import URLInfo from "@src/constants/URLInfo";
 import { IFilter } from "metarare";
+import { useIsFirstRender } from "usehooks-ts";
 
 const cx = classNames.bind(styles);
 
 interface IOwnProps {}
 
 const Explore: React.FC<IOwnProps> = ({}) => {
+  const isFirstRender = useIsFirstRender();
   const dispatch = useDispatch();
   const { list, isExploreListLoaded } = useSelector((store) => store.explore);
-
   const searchText = new URLSearchParams(location.search).get(
     URLInfo.SEARCH_PARAM.SEARCH_TEXT
   );
@@ -40,14 +41,13 @@ const Explore: React.FC<IOwnProps> = ({}) => {
       currency_amount_end: filterProps.maxPrice,
       currency_amount_start: filterProps.minPrice,
       network: filterProps.networkType,
-      sale_type: filterProps.saleType
+      sale_type: filterProps.saleType,
     };
-
     if (searchText) {
       dispatch(
         fetchExploreSearch({
           ...commonBody,
-          token_name: searchText
+          token_name: searchText,
         })
       );
     } else {
@@ -59,7 +59,7 @@ const Explore: React.FC<IOwnProps> = ({}) => {
     {
       list,
       dispatchFnc: dispatchExploreHome,
-      setSelectedFilterType: filterProps.setSelectedFilterType
+      setSelectedFilterType: filterProps.setSelectedFilterType,
     }
   );
 
@@ -74,8 +74,9 @@ const Explore: React.FC<IOwnProps> = ({}) => {
   });
 
   useEffect(() => {
+    if (isFirstRender) return;
     fetchInit();
-  }, [location.search]);
+  }, [searchText]);
 
   return (
     <div className={cx("explore")}>