Returning query options in loaderDeps to prevent duplication
When using tanstack query with tanstack router all the examples duplicate the query options between the
ensureQueryData and useSuspenseQuery as below.
Is there any issues with returning the query options in loaderDeps?
This is particularly useful when we need to use search parameters in our query options like below
1 Reply
exotic-emerald•11mo ago
i would recommend using the
context function instead
context is executed the same way as loader , so if you supply a queryFn in the query options and that queryFn e.g. binds a value, you are only creating that function once. so inside of your component, you do not re-render since the queryFn and queryOptions are referentially stable