[Question/Suggestion] React hooks params order
lucas-santosP opened this issue · 2 comments
Why the react hooks have the ZodiosRequestOptions
as the first param? Wouldn't be more intuitive and cleaner if the QueryOptions
comes first?
Now:
function use[Alias](config?: ZodiosRequestOptions, queryOptions: QueryOptions)
To be:
function use[Alias](queryOptions?: QueryOptions, config?: ZodiosRequestOptions)
Motivation:
Currently, it is necessary to add an undefined
as the first param to access only the query option, which is kinda annoying. And I personally don't see the ZodiosRequestOptions
access having more importance than the QueryOptions
when using a query.
Is pretty common to have to set staleTime, enabled, and initialData for each hook:
Ex:
const colors = apiHooks.useGetColors(undefined, { staleTime: 500, enabled: !!value });
And in the other hand until now I personally didn't find it necessary to access ZodiosRequestOptions
in the hook call.
NOTE: I'm only referring to queries here, but the same applies to mutations.
Hello,
Thank you for the suggestion.
The other way around IS also common. Users with crafted query defaults but with api params.
I have no evidence that one is more used than another.
I have hints that current order is ok because tRPC has chosen the same order.
It would also be a breaking change.
So i'll stick with current order for v10.
For v11 i may change interface completely to only have one parameter :
function use[Alias](options?: QueryOptions & { zodios ?: ZodiosRequestOptions})
Got it, tRPC is a good parameter to follow. And yes my suggestion would be for future releases.
Only one object param is definitely the best option, you'll just need to make sure there's no name collision... to avoid that, separating them into two objects would also be good:
function use[Alias](options?: { query?: QueryOptions; request?: ZodiosRequestOptions })