How to use `useSuspenseQuery` to ensure data is always there?
Hey all. I'm working on an app where basically each screen is bound to be accessed if the user is in an account. I want to develop a hook that will provide the account data and avoid doing undefined checks. Right now, I grad the account id from the url, pass it to a query where and use
enabled
to decide if the query should be called. It is called each time but the undefined checks are annoying. Another approach is to retun null
early if (!accountId)
, which is also annoying.
Here is what I have so far:
The thing is, params.get('account')
might not be defined, in which case I want to redirect the user to one of their accounts.
My problem is that useSuspenseQuery
does not allow for enabled
and I have to do accountId ?? ''
which causes an extra call to be made. I feel like this is a common issue, just not sure how to get around it.
Thanks!1 Reply
frail-apricotOP•15mo ago
This is how it's going but I like it even less than then previous one...