-
I've been toying with an idea but not sure if it's a good one. Unfortunately, I haven't been able to find anything on google about it so hope ya'll can tell me if I'm being stupid. I'm using useQuery to grab a set of data from the backend, but then I need to manipulate that data on the frontend to transform it into a few different views. I'd like to avoid re-calculating unless the returned data has changed. I first reached for useMemo, but realized that would recalculate the data on each unmount/remount which is unnecessary. So I've been thinking about storing the transformed data in react query so any component can access the cached data. The transformed data would have an infinite staleTime and would only get recalculated if useQuery returns new data from the backend. My guess is that a state management library would be a better tool for the job, but we don't currently have one in the codebase. React query has been sufficient for us so far. Thoughts? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Redux is always a better option. If you don't wanna use that, maybe use select option in useQuery, convert the response into the view you want, and return that object and the data you will get from the api will return that object only. const { |
Beta Was this translation helpful? Give feedback.
-
you are likely looking for the |
Beta Was this translation helpful? Give feedback.
you are likely looking for the
select
option: