T
TanStack4y ago
genetic-orange

useQuery helper functions to access returned data?

So we have an API request that fetches two large maps. We have many helper functions like this across the app, keeping the large maps in one scope but importing these util functions around. We are in the process of making this API fetch to useQuery and stuck wondering whats the best way to return helper functions that access that data?
getTokenByMint: (mint: string): MinimalTokenInfo | undefined => {
return tokenMap[mint];
},
getTokenBySymbol: (symbol: string): MinimalTokenInfo | undefined => {
const mint = tokenSymbolMap[symbol];
return tokenMap[mint];
},
getTokenByMint: (mint: string): MinimalTokenInfo | undefined => {
return tokenMap[mint];
},
getTokenBySymbol: (symbol: string): MinimalTokenInfo | undefined => {
const mint = tokenSymbolMap[symbol];
return tokenMap[mint];
},
5 Replies
exotic-emerald
exotic-emerald4y ago
I'd use select.
genetic-orange
genetic-orangeOP4y ago
My understanding is select would mutate the data every time you try to access it. Is that right and the idea approach? To recreate these helper functions many times?
exotic-emerald
exotic-emerald4y ago
Not sure what you mean with "mutate"? Select should work in an immutable way and just return stuff..
genetic-orange
genetic-orangeOP4y ago
ah Okay. Is it safe to assume that lets say I use this query in many different components. When there is fresh data refresh, would all components have the most recent version of these helper methods return from select?
exotic-emerald
exotic-emerald4y ago
Yes? I don't fully understand what you're trying to do

Did you find this page helpful?