v5 issue
Hi there,
I have a followig hook:
no matter what i do there is a TS error:
Type '(data: CurrencyData) => { label: string; value: any; }[]' is not assignable to type '(data: CurrencyData) => CurrencyData'.ts(2769)
queryClient-13f81fcb.d.ts(415, 5): The expected type comes from property 'select' which is declared here on type 'UndefinedInitialDataOptions<CurrencyData, Error, CurrencyData, QueryKey>'
queryClient-13f81fcb.d.ts(415, 5): The expected type comes from property 'select' which is declared here on type 'DefinedInitialDataOptions<CurrencyData, Error, CurrencyData, QueryKey>'
queryClient-13f81fcb.d.ts(415, 5): The expected type comes from property 'select' which is declared here on type 'UseQueryOptions<CurrencyData, Error, CurrencyData, QueryKey>'
Is this smth with implementation? v3 did not give me that errors... how can i fix it?
13 Replies
ratty-blush•3y ago
Pretty sure you can just let
useQuery infer, but onSuccess and onError are removed in v5.
https://tkdodo.eu/blog/breaking-react-querys-api-on-purposeBreaking React Query's API on purpose
Why good API design matters, even if it means breaking existing APIs in the face of resistance.
like-goldOP•3y ago
Ok, yeah well explained, only thing i could not find was how to refactor data returned, so far used to work with select, how shall i handle that in v5
ratty-blush•3y ago
Not sure, I think
select remained relatively unchangedratty-blush•3y ago
Dominik wrote this blog about data transformations if it helps
https://tkdodo.eu/blog/react-query-data-transformations
React Query Data Transformations
Learn the possibilities to perform the quite common and important task of transforming your data with react-query
like-goldOP•3y ago
no it did not... there is an error:

like-goldOP•3y ago
Sorry, my bad... i typed in a wrong way, last thing: again comming back to my hook which works now: how can show loader ? i am not sure how to get access to isLoading, isFetching etc?
ratty-blush•3y ago
They'd all be on your
currencies variablelike-goldOP•3y ago
sorry to be a pain but not sure about it, i mean i can to smth like useEffect(() => {
if (currencies.error) {
toast.error("Something went wrong");
}
}, [currencies.error]);```
ratty-blush•3y ago
Doing it that way turns
currencies into just your data, not the entire useQuery result. You can either do what you had as currencies.isFetching or destruct all the variables you want:
like-goldOP•3y ago
Mint! all works, massive thank you @troywoy just wondering would u know when would be the best time to set currencies to Zustand store? I am using Next.js and checking some possible options
ratty-blush•3y ago
The first link I sent you should give you some ideas on approaches to take
like-goldOP•3y ago
great! will have a look, and the last thing: how can i set refresh data every 24 hours? Shall i set stale?
ratty-blush•3y ago
Yeah
staleTime should work