mirror of
https://github.com/strapi/strapi.git
synced 2025-12-17 18:25:40 +00:00
useRelation/ normalizeRelations: Handle 204 response code properly
This commit is contained in:
parent
16efdef61c
commit
9e4433f881
@ -12,7 +12,7 @@ export const normalizeRelations = (
|
|||||||
pages:
|
pages:
|
||||||
relations?.data?.pages
|
relations?.data?.pages
|
||||||
?.map((page) => [
|
?.map((page) => [
|
||||||
...[...page.results, ...(modifiedData?.connect ?? [])]
|
...[...(page?.results ?? []), ...(modifiedData?.connect ?? [])]
|
||||||
.map((relation) => {
|
.map((relation) => {
|
||||||
const nextRelation = { ...relation };
|
const nextRelation = { ...relation };
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,8 @@ export const useRelation = (cacheKey, { relation, search }) => {
|
|||||||
const relationsRes = useInfiniteQuery(['relation', cacheKey], fetchRelations, {
|
const relationsRes = useInfiniteQuery(['relation', cacheKey], fetchRelations, {
|
||||||
enabled: !!relation?.endpoint,
|
enabled: !!relation?.endpoint,
|
||||||
getNextPageParam(lastPage) {
|
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;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user