You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the optimal pattern for utilising SWR to perform dynamic parallel requests in a single component (or at a parent level). Currently, SWR doesn't support something similar to React Query's useQueries function (https://react-query.tanstack.com/guides/parallel-queries).
For instance, say I have a filtering system that returns a list of product IDs [1, 2, 3] and I need to simultaneously fetch data from an API that can only take in a single query string i.e. {origin}/products?product_id=1.
Currently, the best solution I have been able to come up with involves utilising Promise.all() (code below), however this has several drawbacks: 1. It involves some really ugly string splitting as you cannot pass an array as into the function as an argument (see here - https://swr.vercel.app/docs/arguments) and it also doesn't properly leverage the cache, because the returned data is stored as a single value, not separate values.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
What is the optimal pattern for utilising SWR to perform dynamic parallel requests in a single component (or at a parent level). Currently, SWR doesn't support something similar to React Query's useQueries function (https://react-query.tanstack.com/guides/parallel-queries).
For instance, say I have a filtering system that returns a list of product IDs [1, 2, 3] and I need to simultaneously fetch data from an API that can only take in a single query string i.e. {origin}/products?product_id=1.
Currently, the best solution I have been able to come up with involves utilising Promise.all() (code below), however this has several drawbacks: 1. It involves some really ugly string splitting as you cannot pass an array as into the function as an argument (see here - https://swr.vercel.app/docs/arguments) and it also doesn't properly leverage the cache, because the returned data is stored as a single value, not separate values.
// a utility fetcher function
// how it would be implemented in a component.
Many thanks in advance for any input.
Beta Was this translation helpful? Give feedback.
All reactions