diff --git a/src/config/keys.ts b/src/config/keys.ts index ef0c1a87..e0ee514f 100644 --- a/src/config/keys.ts +++ b/src/config/keys.ts @@ -43,7 +43,7 @@ export const buildItemsChildrenKey = (ids: UUID[]) => [ 'children', hashItemsIds(ids), ]; -export const buildItemDescendantsKey = (id: UUID) => [ +export const buildItemDescendantsKey = (id?: UUID) => [ ITEMS_CONTEXT, 'descendants', id, diff --git a/src/hooks/item.ts b/src/hooks/item.ts index 4e2b2f54..a1407b4c 100644 --- a/src/hooks/item.ts +++ b/src/hooks/item.ts @@ -250,11 +250,16 @@ export default ( }); }, - useDescendants: ({ id, enabled }: { id: UUID; enabled?: boolean }) => { + useDescendants: ({ id, enabled }: { id?: UUID; enabled?: boolean }) => { const queryClient = useQueryClient(); return useQuery({ queryKey: buildItemDescendantsKey(id), - queryFn: () => Api.getDescendants({ id }, queryConfig), + queryFn: () => { + if (!id) { + throw new UndefinedArgument(); + } + return Api.getDescendants({ id }, queryConfig); + }, onSuccess: async (items) => { if (items?.length) { // save items in their own key