-
My project takes advantage of While debugging a potential perf issue in our code, I happened to notice that I know that my code should be prepared to render whenever - even if called redundantly with the same properties. This leads to my questions.
const defaultedQueries = useMemo(() => queries.map(options => {
const defaultedOptions = queryClient.defaultQueryObserverOptions(options)
// Make sure the results are already in fetching state before subscribing or updating options
defaultedOptions.optimisticResults = true
return defaultedOptions
}), [queries]) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I do think that this is indeed a bug / not ideal behaviour of useQueries. At leat the effect dependency is superfluous because, as you said, since we However, does running the effect really trigger another re-render? Because if that were the case, we would likely be looking at an infinite loop, because with an additional re-render, the
yes it could, but it would also shift the responsibilities to consumers of
or just with an inline array with multiple entries, so if that happens, we'd just get a new of course, if it enables an optimization for consumers (they memoize their input, gaining something because if it), we could do that. The question from above remains: What does calling the effect in every render really do? A codesandbox reproduction would be appreciated. |
Beta Was this translation helpful? Give feedback.
I do think that this is indeed a bug / not ideal behaviour of useQueries. At leat the effect dependency is superfluous because, as you said, since we
.map
, the effect will run in every render anyhow.However, does running the effect really trigger another re-render? Because if that were the case, we would likely be looking at an infinite loop, because with an additional re-render, the
useQueries
hook would be called again, scheduling the effect again ...yes it could, but it would also shift the responsibilities to consumers of
useQueries
. Most people call it with: