mirror of
https://github.com/narrrl/holy-flavor-rater.git
synced 2026-11-03 16:41:27 +01:00
fixed map bug
This commit is contained in:
1 parent
fa37f8eb79
commit
c121380c6e
1 file changed
+7
-4
@@ -30,12 +30,15 @@ export interface CategoryItem {
|
|||||||
slug: string;
|
slug: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const unwrap = <T>(data: T[] | { results?: T[] }): T[] =>
|
||||||
|
Array.isArray(data) ? data : (data.results ?? []);
|
||||||
|
|
||||||
export const useFlavorsList = () =>
|
export const useFlavorsList = () =>
|
||||||
useQuery({
|
useQuery({
|
||||||
queryKey: queryKeys.flavors({ scope: 'all' }),
|
queryKey: queryKeys.flavors({ scope: 'all' }),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await api.get<FlavorListItem[]>('flavors/');
|
const res = await api.get<FlavorListItem[] | { results: FlavorListItem[] }>('flavors/');
|
||||||
return res.data;
|
return unwrap(res.data);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -43,8 +46,8 @@ export const useCategories = () =>
|
|||||||
useQuery({
|
useQuery({
|
||||||
queryKey: ['categories'],
|
queryKey: ['categories'],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await api.get<CategoryItem[]>('categories/');
|
const res = await api.get<CategoryItem[] | { results: CategoryItem[] }>('categories/');
|
||||||
return res.data;
|
return unwrap(res.data);
|
||||||
},
|
},
|
||||||
staleTime: 5 * 60_000,
|
staleTime: 5 * 60_000,
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user