StrictNullCheck and dependant queries
Hi, me again !
I am working with typescript strict mode, and I am not sure what would be an elegant solution to handle dependant queries.
I have typesafe abstracted queries that require data to be set:
- useGetDetails
- useGetBillingInfoById requires
pathParams.location_group_id
to be a string
Here is an example:
(1) Making weird condition that satisfy typesafety
(2) Have optional types on useGetBillingInfoById
for the property pathParams.location_group_id
(3) Define initialData, but usually I have to define the whole data
(4) ?
Thank a lot ! :))3 Replies
wise-white•15mo ago
4: extract whatever depends on "infoQuery" into a separate component with "default_location_group_id" prop?
xenial-blackOP•15mo ago
@wlnt its a solution yes and most of the times we want to achieve that.
However that's not always possible, or at least it reduces the flexibility of composition of your components / hooks.
sensitive-blue•15mo ago
use the
skipToken
: https://tanstack.com/query/latest/docs/framework/react/guides/disabling-queries#typesafe-disabling-of-queries-using-skiptokenDisabling/Pausing Queries | TanStack Query React Docs
If you ever want to disable a query from automatically running, you can use the enabled = false option. The enabled option also accepts a callback that returns a boolean.
When enabled is false: