Skip to content

Why pageParams is undefined on init? #3442

Answered by TkDodo
behzadam asked this question in General
Discussion options

You must be logged in to vote

pageParam is derived from the previous page via getNextPageParam. Since the first page has no previous page, what else should it be?

That is why we assign a default value in the example:

useInfiniteQuery(
    'projects',
    async ({ pageParam = 0 }) => {
      const res = await axios.get('/api/projects?cursor=' + pageParam)
      return res.data
    },
    {
      getNextPageParam: lastPage => lastPage.nextId ?? undefined,
    }
  )

in that case, undefined gets coerced to 0

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@behzadam
Comment options

@amirfrd
Comment options

@TkDodo
Comment options

@sbbu
Comment options

@TkDodo
Comment options

Answer selected by behzadam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants