Skip to content

Commit

Permalink
hotfix(codegen): hotfix useAllObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
Alllex202 committed Oct 2, 2024
1 parent 41d8858 commit 23ac0cb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/codegen/generate.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ export function generateReactHooks<

function useAllObjects (variables: QueryVariables, options?: QueryHookOptions<IUseObjectsQueryReturnType<GQLObject>, QueryVariables>) {
const fetchPolicy = get(options, 'fetchPolicy')
const skip = get(options, 'skip')
const { objs, count, error, loading, refetch: _refetch, fetchMore, stopPolling } = useObjects(variables, {
...options,
fetchPolicy: fetchPolicy && fetchPolicy !== 'no-cache' ? fetchPolicy : 'network-only',
Expand Down Expand Up @@ -414,20 +415,22 @@ export function generateReactHooks<
}, [fetchMore])

useEffect(() => {
if (skip) return
if (!loading && !firstPageLoaded) {
setData(objs)
setFirstPageLoaded(true)
}
}, [objs, loading, firstPageLoaded])
}, [objs, loading, firstPageLoaded, skip])

useEffect(() => {
if (skip) return
if (!firstPageLoaded) return
if (data.length === 0) return
if (count <= data.length) return
if (error || fetchMoreError) return

loadMore(data.length)
}, [count, data.length, error, fetchMoreError, firstPageLoaded, loadMore])
}, [count, data.length, error, fetchMoreError, firstPageLoaded, loadMore, skip])

return {
loading,
Expand Down

0 comments on commit 23ac0cb

Please sign in to comment.