Skip to content

Commit 5c3f8f7

Browse files
committed
Refactor to avoid refetch
1 parent 13aa9b0 commit 5c3f8f7

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

Diff for: src/hooks.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ export function useGetRestaurantList(filtersParams: {
1818
async (): Promise<PreviewList> => {
1919
const prom: JSON = await getRestaurantList(filtersParams);
2020
return fromJsonToPropPreview(prom);
21-
},
22-
{ enabled: false }
21+
}
2322
);
2423
}
2524

Diff for: src/pages/Home.tsx

+6-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { useGetRestaurantList } from "../hooks";
1616
import RestaurantPreview from "../components/RestaurantPreview";
1717
import { useTranslation } from "react-i18next";
1818
import { validators, useFormo, success } from "@buildo/formo";
19-
import { useEffect } from "react";
19+
import { useState } from "react";
2020
import { PreviewPropComponent } from "../models";
2121

2222
function Home() {
@@ -27,7 +27,9 @@ function Home() {
2727
radius: 10,
2828
};
2929

30-
const { fieldProps, handleSubmit, values } = useFormo(
30+
const [activeFilters, setActiveFilters] = useState(initialValues);
31+
32+
const { fieldProps, handleSubmit } = useFormo(
3133
{
3234
initialValues,
3335
fieldValidators: () => ({
@@ -36,17 +38,13 @@ function Home() {
3638
},
3739
{
3840
onSubmit: async (values) => {
39-
refetch();
41+
setActiveFilters(values);
4042
return success(values);
4143
},
4244
}
4345
);
4446

45-
useEffect(() => {
46-
refetch();
47-
}, []); // eslint-disable-line react-hooks/exhaustive-deps
48-
49-
const { isLoading, isError, data, refetch } = useGetRestaurantList(values);
47+
const { isLoading, isError, data } = useGetRestaurantList(activeFilters);
5048

5149
if (isLoading) {
5250
return <AreaLoader message="Loading..."></AreaLoader>;

0 commit comments

Comments
 (0)