useRelation/ normalizeRelations: Handle 204 response code properly

This commit is contained in:
Gustav Hansen 2022-09-08 11:57:51 +02:00
parent 16efdef61c
commit 9e4433f881
2 changed files with 3 additions and 2 deletions

View File

@ -12,7 +12,7 @@ export const normalizeRelations = (
pages:
relations?.data?.pages
?.map((page) => [
...[...page.results, ...(modifiedData?.connect ?? [])]
...[...(page?.results ?? []), ...(modifiedData?.connect ?? [])]
.map((relation) => {
const nextRelation = { ...relation };

View File

@ -40,7 +40,8 @@ export const useRelation = (cacheKey, { relation, search }) => {
const relationsRes = useInfiniteQuery(['relation', cacheKey], fetchRelations, {
enabled: !!relation?.endpoint,
getNextPageParam(lastPage) {
if (lastPage.pagination.page >= lastPage.pagination.pageCount) {
// the API may send an empty 204 response
if (!lastPage || lastPage.pagination.page >= lastPage.pagination.pageCount) {
return undefined;
}