-
If I use useQueries() to retrieve data from a number of different sources, that I want to merge in combine, is the order of the items in combine always ensured? considering the below example, I have 3 different dataFetches that all returns an object with key/value pairs, that I want to merge in a specific order, so keys in fetchData2 can overwrite keys received in fetchData1, and likewise fetchData3 can override keys received in fetchData1 or fetchData2. Is this correct? Or should I have some extra indicator in my data from each queryFn that indicates which query method is handled? Also what happens if f.ex. queryKey 'data-2' is invalidated / removed, will it keep the same order in combine? const x = useQueries({
queries: [
{ queryKey: 'data-1', queryFn: () => fetchData1() }
{ queryKey: 'data-2', queryFn: () => fetchData2() }
{ queryKey: 'data-3', queryFn: () => fetchData3() }
],
combine: (data) => {
return data.reduce((result, current) => {
return Object.assign(result, current.data)
}, {})
}) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
How do you share code like that? I mean, your code is colorful :) |
Beta Was this translation helpful? Give feedback.
-
yes, the order you get into |
Beta Was this translation helpful? Give feedback.
yes, the order you get into
combine
is the same as the order inqueries