redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

Lazy infinite queries hook

Open Innders opened this issue 7 months ago • 4 comments

The ability to use infinite queries with a lazy hook just like normal lazy queries.

useLazyGetPokemonInfiniteQuery.

Use case

The ability to get the data from multiple different arguments. Currently there is no way to dynamically call the infiniteQuery for with different arguments as hooks are not loopable.

const [getPokemon] = useLazyGetPokemonInfiniteQuery()

  for (const type in types) {
    getPokemon(type)
  }

Issues

How do you deal with the fetchNextPage

Innders avatar May 30 '25 08:05 Innders

This looks like a bit of an "X/Y problem" kind of request.

Lazy queries aren't meant for looping and triggering many requests in a row.

What's your use case for making multiple requests like that?

markerikson avatar May 31 '25 01:05 markerikson

Maybe the use case is a bit niche I will admit.

The use case for loading grouped table data. The groups are completely dynamic and each group needs to fetch all it's own items. A group can have 1000+ items in it so there needs to be some kind of pagination involved.

But maybe i'm thinking about it all wrong!

Innders avatar May 31 '25 08:05 Innders

But the point of pagination is usually that you don't get all the pages, but just the page that's currently on screen. Otherwise you're back at square one: the server does a lot of useless work and your browser memory fills up with stuff that's currently irrelevant.

phryneas avatar May 31 '25 10:05 phryneas

I ended up here because I'm facing a similar issue. In my case, I need to re-trigger the full pagination and reset it to page one when filtering the list, and I also need some form of debounce for the search input.

LuizCristino avatar Jun 26 '25 18:06 LuizCristino