diff --git a/src/hooks.tsx b/src/hooks.tsx index 7def5fb..4ccf5b2 100644 --- a/src/hooks.tsx +++ b/src/hooks.tsx @@ -11,15 +11,14 @@ export function useGetRestaurantList(filtersParams: { return useQuery( [ "restaurantList", - filtersParams.location.toString, - filtersParams.radius.toString, - filtersParams.prices.toString, + filtersParams.location, + filtersParams.radius, + filtersParams.prices, ], async (): Promise => { const prom: JSON = await getRestaurantList(filtersParams); return fromJsonToPropPreview(prom); - }, - { enabled: false } + } ); } diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 3ba3e68..3fb1b14 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -16,7 +16,7 @@ import { useGetRestaurantList } from "../hooks"; import RestaurantPreview from "../components/RestaurantPreview"; import { useTranslation } from "react-i18next"; import { validators, useFormo, success } from "@buildo/formo"; -import { useEffect } from "react"; +import { useState } from "react"; import { PreviewPropComponent } from "../models"; function Home() { @@ -27,7 +27,9 @@ function Home() { radius: 10, }; - const { fieldProps, handleSubmit, values } = useFormo( + const [activeFilters, setActiveFilters] = useState(initialValues); + + const { fieldProps, handleSubmit } = useFormo( { initialValues, fieldValidators: () => ({ @@ -36,17 +38,13 @@ function Home() { }, { onSubmit: async (values) => { - refetch(); + setActiveFilters(values); return success(values); }, } ); - useEffect(() => { - refetch(); - }, []); // eslint-disable-line react-hooks/exhaustive-deps - - const { isLoading, isError, data, refetch } = useGetRestaurantList(values); + const { isLoading, isError, data } = useGetRestaurantList(activeFilters); if (isLoading) { return ;