SaraS
Convex Community4mo ago
13 replies
Sara

Proper Validation to getting all data created in the last week with `.withIndex` and pagination

I'm using luxon to do time calculations, and this is first time I've run into this issue,
I have a usePaginatedQuery imported from cache provider from convex-helpers with next.js latest, and I'm running the following query below, the userId is coming from the ctx, and the DateTime is coming from luxon, built on top of index,
when I add the last gte for the field _creationTime I get an infinite loop on my frontend
Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.

I've tested the query and its working for a sure, but somehow its causing my frontend to overreact,

export const listAllByUserId = authenticatedQuery({
  args: { paginationOpts: paginationOptsValidator },
  handler: async (ctx, args_0) => {
    const cutoff = DateTime.now().minus({ days: 7 }).toMillis();
    const all = await ctx.db.query("shoppingLists")
++      .withIndex("by_creatorId", q => q.eq("creatorId", ctx.user._id).gte("_creationTime",cutoff)) 
--      .withIndex("by_creatorId", q => q.eq("creatorId", ctx.user._id)) 
      .order("desc")
      .paginate(args_0.paginationOpts);
      
    return all
  },
})
Was this page helpful?