TanStackT
TanStack3y ago
6 replies
faint-white

useInfiniteQuery pageParams always undefined

I am trying to get a useInfiniteQuery hook working by setting the pageParams to a string that i pass to our endpoint, but pageParams is always undefined.

Does pageParams need to be a number? We use a string of the next id to fetch but it doesnt set it..

export const useInfiniteCustomers = ({
  companyId,
  ucId,
  role,
  cancel = false,
}: {
  companyId: string
  ucId: string
  role: string
  exclusiveStartKey?: string
  cancel?: boolean
}) => {
  return useInfiniteQuery({
    queryKey: ['getInfiniteCustomers', { companyId, ucId, role }],
    queryFn: async ({ pageParam }) => {
      const { data } = await CustomersAPI.getInfiniteCustomers({
        companyId,
        ucId,
        role,
        ...(pageParam && pageParam !== undefined && { exclusiveStartKey: pageParam }),
        cancel,
      })

      return data.listCustomerReferencesByRole
    },
    // enabled: !!companyId && !!ucId && !!role,
    getNextPageParam: (lastPage: any, allPages) => {
      console.log('lastPage', lastPage)
      return lastPage?.nextExclusiveStartKey ?? undefined
    },
    staleTime: Infinity,
  })
}
Was this page helpful?