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;
|
||||
}
|
||||
|
||||
const unwrap = <T>(data: T[] | { results?: T[] }): T[] =>
|
||||
Array.isArray(data) ? data : (data.results ?? []);
|
||||
|
||||
export const useFlavorsList = () =>
|
||||
useQuery({
|
||||
queryKey: queryKeys.flavors({ scope: 'all' }),
|
||||
queryFn: async () => {
|
||||
const res = await api.get<FlavorListItem[]>('flavors/');
|
||||
return res.data;
|
||||
const res = await api.get<FlavorListItem[] | { results: FlavorListItem[] }>('flavors/');
|
||||
return unwrap(res.data);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -43,8 +46,8 @@ export const useCategories = () =>
|
||||
useQuery({
|
||||
queryKey: ['categories'],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<CategoryItem[]>('categories/');
|
||||
return res.data;
|
||||
const res = await api.get<CategoryItem[] | { results: CategoryItem[] }>('categories/');
|
||||
return unwrap(res.data);
|
||||
},
|
||||
staleTime: 5 * 60_000,
|
||||
});
|
||||
Reference in new issue
Block a user