소스 검색

Fix package state initialization and update effect deps

Initialize the 'packages' state as an empty array instead of null and update the useEffect dependency array to include 'area' for correct data fetching when 'area' changes.
hieubt 3 주 전
부모
커밋
1ce1f3b3b9
1개의 변경된 파일2개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 2
      EsimLao/esim-vite/src/pages/product-detail/ProductDetailView.tsx

+ 2 - 2
EsimLao/esim-vite/src/pages/product-detail/ProductDetailView.tsx

@@ -33,7 +33,7 @@ const ProductDetailView: React.FC = () => {
   });
   const [simType, setSimType] = useState<"eSIM" | "Physical">("eSIM");
   const [quantity, setQuantity] = useState<number>(1);
-  const [packages, setPackages] = useState<Package[]>(null);
+  const [packages, setPackages] = useState<Package[]>([]);
 
   if (!area) {
     return (
@@ -71,7 +71,7 @@ const ProductDetailView: React.FC = () => {
 
   useEffect(() => {
     getProductMutation.mutate();
-  }, []);
+  }, [area]);
 
   const getProductMutation = useMutation({
     mutationFn: async () => {