Why using multiple useQuery with Suspense in single component cause water fall? #4493
-
Hi, thank you for fantastic library! I saw this Q&A, and understood why water fall problem caused.
Also saw recent tkdodo blog post :) So component repeat mount-unmount each useQuery declarations. but why this happens only in react query useQuery api ? what I trying to say is water fall doesn't happen when using custom Is there any special implementation in useQuery function wrapPromise(promise) {
let status = "pending";
let result;
let suspender = promise.then(
(r) => {
status = "success";
result = r;
},
(e) => {
status = "error";
result = e;
}
);
return {
read() {
if (status === "pending") {
throw suspender;
} else if (status === "error") {
throw result;
} else if (status === "success") {
return result;
}
}
};
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Your instantiation of:
outside of the component tree is the equivalent of prefetching there, because you trigger |
Beta Was this translation helpful? Give feedback.
Your instantiation of:
outside of the component tree is the equivalent of prefetching there, because you trigger
fetchUser
andfetchPosts
immediately.