This is my first time using Apollo Client so I’m still getting familiar with things. I need to make a combined query which fetches two types of data: Posts and Adverts. Both of these are arrays of data and once I have the data fetched from the remote source I need to merge the two arrays at a specific frequency (a separate JS function). This will result in a single array of data which is to be used as the content for my page in a Next.js application.
My question is how is it best to handle that combined array of data? Should I store it in React state, use Apollo Reactive Variables, or write to cache?
To provide a little extra info on the usage:
- This combined data will be passed to a couple of other components which need to re-render when the content changes.
- I need data to be fetched automatically on initial page load, after that it will be triggered based on user interaction (interacting with a search form and clicking Submit, or use pagination controls to page through the data)
- Every time a user submits a new search I need to make sure I fetch the remote data according to the search criteria they’ve entered so this will alter the Post data that is returned and a new combined array needs to be created accordingly.
Any advice is greatly appreciated.