-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.tsx
34 lines (32 loc) · 974 Bytes
/
hooks.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { useQuery } from "@tanstack/react-query";
import { getRestaurantList, getRestaurantDetails } from "./api";
import { fromJsonToPropPreview, fromJsonToPropDetails } from "./utils";
import { PreviewList, DetailsPropApi } from "./models";
export function useGetRestaurantList(filtersParams: {
prices: string[];
location: string;
radius: number;
}) {
return useQuery(
[
"restaurantList",
filtersParams.location.toString,
filtersParams.radius.toString,
filtersParams.prices.toString,
],
async (): Promise<PreviewList> => {
const prom: JSON = await getRestaurantList(filtersParams);
return fromJsonToPropPreview(prom);
},
{ enabled: false }
);
}
export function useGetRestaurantDetails(id: string) {
return useQuery(
["restaurantDetails", id],
async (): Promise<DetailsPropApi> => {
const prom: JSON = await getRestaurantDetails(id);
return fromJsonToPropDetails(prom);
}
);
}