blog/inside-react-query #89
Replies: 20 comments 23 replies
-
Great write-up! I was looking for something exactly like this |
Beta Was this translation helpful? Give feedback.
-
Hi great blog, thanks! const [observer] = React.useState(
() =>
new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(
queryClient,
defaultedOptions,
),
) |
Beta Was this translation helpful? Give feedback.
-
Can you explain a bit about notifyManager? |
Beta Was this translation helpful? Give feedback.
-
Two months back I texted you in twitter asking about this. Now it is here. Thanks for your commitment. Great blog. |
Beta Was this translation helpful? Give feedback.
-
Yo thanks for making it look so simple!! This is an awesome library. |
Beta Was this translation helpful? Give feedback.
-
Thanks so much for the explanation. Btw. what program did you use to create the charts? They are beautiful and I'd like to create similar ones =) |
Beta Was this translation helpful? Give feedback.
-
Thank you Dominik! always good to be backstage 😎 |
Beta Was this translation helpful? Give feedback.
-
Hi! Can you explain how you force react to rerender, when data is loaded or when refetch called? |
Beta Was this translation helpful? Give feedback.
-
That was a great article! After using RQ a lot for the past months, It is nice to understand how it works under the hood. Thanks a lot! |
Beta Was this translation helpful? Give feedback.
-
Great article! 🚀 So the Thanks 🙏 |
Beta Was this translation helpful? Give feedback.
-
Hi, thank you for writing a great article :) What I understood is: I found that when using I think it could be on render phase instead of effect phase. Because useEffect is called after rendering is done, "triggered in useEffect" vs "triggered while rendering" will have a performance difference (yes, it will be small - about 10ms, though. 😅). like this way (briefly writed) // as is
// of course, indeed - here are many many more complex steps & options
const useQuery = (queryFn) => {
useEffect(() => {
queryFn(); // <- called while effect phase
}, [queryFn]);
}
// to be
// something like this would be better in performance
const useQuery = (queryFn) => {
const prevRef = useRef();
if (someConditionCalculatedFromPrevRefCurrentValue) queryFn(); // <- called while rendering phase
} This would be a terrible code in plain react, but react-query uses its own observer, so this pattern seems not that wierd. So my question is: is this behavior intended despite this can lead to a little poor performance? Again, thank you for a great article and library! I love tanstack query :) |
Beta Was this translation helpful? Give feedback.
-
It's awesome! |
Beta Was this translation helpful? Give feedback.
-
How does it know which fields are being tracked? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the great article! |
Beta Was this translation helpful? Give feedback.
-
I love it! Thanks for this. I have a question, how do you handle clean ups on useMutation? Do you use fetch API in the background, how do you handle abort controllers? |
Beta Was this translation helpful? Give feedback.
-
I guess you mean unsubcribe callbacks like in useEffect, then i guess generally it is unsafe to cancel mutations, and it is indeterminated what will happen on cancel, does data changed on the external storage or not. For this reason it is a page in docs about query cancelation and is not about mutation cancelation And if you question about, how making a request happens inside useMutation, you are welcome to explore the source code of it 😄 |
Beta Was this translation helpful? Give feedback.
-
Great explanation of architecture! |
Beta Was this translation helpful? Give feedback.
-
Very well written and clear. I'm impressed. I'm a dev with 6 years experience but still have a hard time grasping architectures and technical details. You laid it out masterfully and was easy to follow along. |
Beta Was this translation helpful? Give feedback.
-
Hi, What is the main question: more context: What is strange to me? Each application is a separate project being mounted/unmounted under the single spa management. |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for your explanation! I have a question: Why do you store the whole object inside the QueryCache class and within a property? Why not use something like WeakMap, which works well with garbage collection? In the codebase, I saw a garbage collection timer that removes the whole object when an observer is removed (I think when the component unmounts). How do you handle storing large objects in memory and manage that effectively? I have a lot of questions about storing data inside class properties versus other options. I noticed the useSWR codebase uses WeakMap internally, and seeing only a class handle all this logic made me wonder about your approach. |
Beta Was this translation helpful? Give feedback.
-
blog/inside-react-query
Taking a look under the hood of React Query
https://tkdodo.eu/blog/inside-react-query
Beta Was this translation helpful? Give feedback.
All reactions