Replies: 7 comments 15 replies
-
For now what I did was passing a query group index to a mutation. Now i know which query group of an item that need to be updated belongs. Next, I looped through that query group to find that will-be-updated item (Immerjs helps a lot). The variables is available as argument on all on-prefix callback. Hope it helps you. I kind of wish the the dev guide us in someway on this topic. My way is kind of usable and demo-able but it feels not scalable somehow. @tannerlinsley Can you help guide us in proper way for this problem ? |
Beta Was this translation helpful? Give feedback.
-
I'm also having the same issue. I use infinite list with potential lots of items and allow to select a few and bulk update them. What is the best way to achieve this? |
Beta Was this translation helpful? Give feedback.
-
Have you found a solution, guys? |
Beta Was this translation helpful? Give feedback.
-
since v3, useInfiniteQuery consists of an object with
given that I have an array of todos on each page, I would use
|
Beta Was this translation helpful? Give feedback.
-
With DRF I have this solution: export function useInfiniteQuery<
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
queryKey: TQueryKey,
baseUrl: string,
params?: Record<string, string>,
options?: Omit<UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, "queryKey" | "queryFn">
) {
const infiniteQueryObject = _useInfiniteQuery<TQueryFnData, TError, TData, TQueryKey>(
queryKey,
async ({pageParam}) => {
const response = await axios.get(pageParam || baseUrl, !pageParam ? {params} : {});
return response.data;
},
{
// TODO: ppr-refactor
getNextPageParam: (lastPage: any) => lastPage?.next,
...options,
}
);
const queryClient = useQueryClient();
function updateQueryData(newData: TData) {
queryClient.setQueryData<InfiniteData<PageData<TData>> | undefined>(queryKey, (data) => {
if (data) {
data.pages = data.pages.map((page) => {
page.results = page.results.map((result) => {
// @ts-ignore
if (result.id === newData.id) {
result = newData;
}
return result;
});
return page;
});
}
return data;
});
}
return {items: transformQueryData<TData>(infiniteQueryObject.data), updateQueryData, ...infiniteQueryObject};
} |
Beta Was this translation helpful? Give feedback.
-
is there other better solution than using map func in map func? |
Beta Was this translation helpful? Give feedback.
-
I happen to share my solution to this on another discussion with the same subject (#3360). This and the said discussion are the top 2 results on Google so I would like share this here as well. |
Beta Was this translation helpful? Give feedback.
-
I have read the docs and the repo issues several times but still can't figure out how to use
queryCache.setQueryData()
to add/update/remove items from anuseInfiniteQuery()
? Not sure what to pass to the first params ofsetQueryData
?It seems for now on mutation success I always have to call
queryCache.invalidateQueries()
which is very wasteful.Some code example would be great. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions