Skip to content

useSWRInfinite multiple arguments like useSWR does #732

Answered by shuding
RSchneider94 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi! The reason is that the first argument of useSWRInfinite has to be a function (but you are passing an array). You can make getKey return an array instead:

const { data, error, size, setSize } = useSWRInfinite(
  (pageIndex, previousPageData) => {
    if (!token) return null;

    // reached the end
    if (previousPageData && !previousPageData.data) return null;
    // first page, we don't have `previousPageData`
    if (pageIndex === 0) return ['/customer_access', token];
    // add the cursor to the API endpoint
    return [`/customer_access?last_slice=${pageIndex}`, token];
  },
  fetcher
);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@RSchneider94
Comment options

Answer selected by RSchneider94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants