Shahen 🔺
Shahen 🔺
CCConvex Community
Created by Shahen 🔺 on 10/16/2024 in #support-community
Paginated query with Tanstack Query
only issue is react query cached data is messing with next cursor data
30 replies
CCConvex Community
Created by Shahen 🔺 on 10/16/2024 in #support-community
Paginated query with Tanstack Query
when i enable refetchInterval, i do see a new query in logs, i set it to 10 seconds and the query appears in logs every 10 secs
30 replies
CCConvex Community
Created by Shahen 🔺 on 10/16/2024 in #support-community
Paginated query with Tanstack Query
no queries in logs when i update a user score in database
30 replies
CCConvex Community
Created by Shahen 🔺 on 10/16/2024 in #support-community
Paginated query with Tanstack Query
@ballingt
const convex = useConvex();

const fetchScores = async (pageParam: string | null) => {
const response = await convex.query(api.scorecards.getScorecards, {
tier: tier,
paginationOpts: {
numItems: 5,
cursor: pageParam,
},
});

return response
};

const { data: infinite, fetchNextPage } = useInfiniteQuery({
queryKey: [`scorecard-${tier}`],
queryFn: ({ pageParam }: { pageParam?: string | null }) => fetchScores(pageParam ?? null),
getNextPageParam: (lastPage) => {
return lastPage.isDone ? undefined : lastPage.continueCursor;
},
initialPageParam: null,
// refetchInterval: 10000
})
const convex = useConvex();

const fetchScores = async (pageParam: string | null) => {
const response = await convex.query(api.scorecards.getScorecards, {
tier: tier,
paginationOpts: {
numItems: 5,
cursor: pageParam,
},
});

return response
};

const { data: infinite, fetchNextPage } = useInfiniteQuery({
queryKey: [`scorecard-${tier}`],
queryFn: ({ pageParam }: { pageParam?: string | null }) => fetchScores(pageParam ?? null),
getNextPageParam: (lastPage) => {
return lastPage.isDone ? undefined : lastPage.continueCursor;
},
initialPageParam: null,
// refetchInterval: 10000
})
this is working, and it doesn't seem to be reactive anymore
30 replies
CCConvex Community
Created by Shahen 🔺 on 10/16/2024 in #support-community
Paginated query with Tanstack Query
Thanks Tom
30 replies
CCConvex Community
Created by Shahen 🔺 on 10/16/2024 in #support-community
Paginated query with Tanstack Query
Alright I’ll look into it and get back to you
30 replies
CCConvex Community
Created by Shahen 🔺 on 10/16/2024 in #support-community
Paginated query with Tanstack Query
or maybe I am missing some benefits that convex offers in that kinda case
30 replies
CCConvex Community
Created by Shahen 🔺 on 10/16/2024 in #support-community
Paginated query with Tanstack Query
I love the reactive data for sure, but I'm thinking if i can make these leaderboards more efficient since I don't necessarily need reactive data for it. it could update every 5 minutes and it'd be fine.
30 replies
CCConvex Community
Created by Shahen 🔺 on 10/16/2024 in #support-community
Paginated query with Tanstack Query
i see
30 replies
CCConvex Community
Created by Shahen 🔺 on 10/16/2024 in #support-community
Paginated query with Tanstack Query
my use case, I have 5 big leaderboards on a single page, I want to set some sort of delay so that i can save on resources
30 replies
CCConvex Community
Created by Shahen 🔺 on 10/16/2024 in #support-community
Paginated query with Tanstack Query
yes for example:
const { data, isPending, error } = useQuery({
...convexQuery(api.functions.myQuery, { id: 123 }),
initialData: [], // use an empty list if no data is available yet
gcTime: 10000, // stay subscribed for 10 seconds after this component unmounts
});
const { data, isPending, error } = useQuery({
...convexQuery(api.functions.myQuery, { id: 123 }),
initialData: [], // use an empty list if no data is available yet
gcTime: 10000, // stay subscribed for 10 seconds after this component unmounts
});
gcTime, is there a way to set that without react query?
30 replies
CCConvex Community
Created by Shahen 🔺 on 10/16/2024 in #support-community
Paginated query with Tanstack Query
can i use useInfiniteQuery? or do i have to use useQuery(from tanstack) and implement my custom way to display and load more?
30 replies
CCConvex Community
Created by Shahen 🔺 on 10/16/2024 in #support-community
Paginated query with Tanstack Query
thanks, but I am looking for an example with tanstack query, what would use as the queryFn for example
30 replies
CCConvex Community
Created by Shahen 🔺 on 10/16/2024 in #support-community
Paginated query with Tanstack Query
hey tom, do you have an example of how to implement it?
30 replies