zidZ
Convex Community3y ago
3 replies
zid

split for paginated queries

trying to implement basic paginated query.
also saw read that "skip" feature does not exist yet for usePaginatedQuery.
with that in mind, i get the following error: TypeError: Cannot read properties of null (reading 'splitCursor')
  // client
  const { results, isLoading, status, loadMore } = usePaginatedQuery(
    api.user.getUserEquips,
    { userId, type: "mana" },
    { initialNumItems: 5 }
  );

// server
export const getUserEquips = query({
  args: {
    paginationOpts: paginationOptsValidator,
    userId: v.union(v.string(), v.null()),
    type: v.union(v.string(), v.null()),
  },
  handler: async ({ db }, { userId, type }) => {
    if (
      userId === null ||
      userId === undefined ||
      type === null ||
      type === undefined
    ) {
      return;
    }

    return await db
      .query("userEquips")
      .withIndex("by_userId_type", (q) =>
        q.eq("userId", userId).eq("type", type)
      )
      .order("desc")
      .paginate(args.paginationOpts);
  },
});

when i pass in a literal value to userId, it works.
so it seems i need to figure out a way to pass in async values/arguments to usePaginatedQuery.
since "skip" is not yet supported, what would you suggest?
Is the only way to initialize the paginated query in a child component of where the userId has been fetched?
Was this page helpful?