Skip to content
Discussion options

You must be logged in to vote

Found the answer. I think I described my use case poorly.

Basically, what I want is to apply the initialData only to the first page. Therefore, I can implement a conditional whether the page is the first page or not.

const { data, error } = useSWR<GraphQLResult, any>(
    [gqlQuery, page],
    (gqlQuery, page) => {
      const variables = {
        query,
        limit: ITEM_PER_PAGE,
        offset: (page - 1) * ITEM_PER_PAGE,
      };

      if (variables.offset) {
        variables.offset += 1;
      }

      return graphQLFetcher<GraphQLVariables>(gqlQuery, variables);
    },
    { initialData: page === 1 ? initialData : null },
  );

Replies: 2 comments 1 reply

Comment options

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

Comment options

You must be logged in to vote
0 replies
Answer selected by Namchee
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