I have a component that uses useQuery from React Query like this:
const { data } = useQuery(
["products", selectedStore],
fetchProductsByStoreId
)
selectedStore is a local state variable that can be changed from the UI, triggering a request to the API for new products. My problem is, that I also need to use the data from the request in another component, preferably via queryCache.getQueryData, but to do this, I need to provide a key, that is not only the string "Products" but the whole array ["products", selectedStore].
The other component does not have access to selectedStore, so my question is, is there a way the other component can access this query data without hoisting selectedStore to global state? I would like to keep the data in the queryCache and not hoist it either.
productsand the cache will only have the latest data. But then u sorta loose the benefits caching and react-query.