Small feature request: option to flatten pages from infinite query #2000
-
Hey @tannerlinsley and team - thanks so much for this library. Had a quick suggestion: would it be possible to add an option to useInfiniteQuery to return a flat array of items rather than an array of pages, which are themselves arrays of items? This would be useful for infinite feeds and would help drive adoption. Here's an example of someone flattening the array manually: https://github.com/erdalstk/react-query-infinite-flatlist-example/blob/19b65114494c86d2d10b178be0405e7b07edcd00/src/hooks/useInfiniteContacts.ts#L19 And here are other discussions mentioning this feature:
I'd take a swing at it myself but still learning the ropes with JS so hoping someone more competent can lead the way. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hello, @crieggalder! I also experienced this lately and yes, maybe it could've been easier to have an option to flatten, but still... the response may carry other important data, other than just the list of items. For example, an infinite query may carry a next page param, such as a cursor, or the total count, or even more data that you might need as an API consumer: filtering or sorting related data, and so on. I think the design right now is well-unopinionated, to leave the developer the freedom to handle the pages at his preference. |
Beta Was this translation helpful? Give feedback.
-
The idea is more something like:
|
Beta Was this translation helpful? Give feedback.
The idea is more something like: