Skip to content

Implementing infinite scroll with RTK Query #1163

Answered by phryneas
davidtkramer asked this question in Q&A
Discussion options

You must be logged in to vote

Copying my answer from there over here so that people find it more easily 🙂 (also, here would be a generally better place to further discuss any upcoming problems since SO doesn't realle encourage much discussion)


I think most implementations overcomplicate the problem of "infinite scroll" by a lot.
You can achieve this by stepping a bit back and thinking about what you really need:

  • the current in-view data
  • a bit extra data into the direction we're scrolling to

Since we are lazy and do not want to track which direction we're scrolling to, just assume

  • the current in-view data
  • a bit extra data into both directions.

Also let's assume the query returns a response like

  {
    offset: 50,

Replies: 33 comments 142 replies

Comment options

You must be logged in to vote
17 replies
@phryneas
Comment options

@Elendil00
Comment options

@spacepolice10
Comment options

@spacepolice10
Comment options

@theobouwman
Comment options

Answer selected by davidtkramer
Comment options

You must be logged in to vote
1 reply
@phryneas
Comment options

Comment options

You must be logged in to vote
1 reply
@gormonn
Comment options

Comment options

You must be logged in to vote
8 replies
@phryneas
Comment options

@taejs
Comment options

@phryneas
Comment options

@taejs
Comment options

@phryneas
Comment options

Comment options

You must be logged in to vote
3 replies
@afgarcia86
Comment options

@afgarcia86
Comment options

@The0racle
Comment options

Comment options

You must be logged in to vote
5 replies
@phryneas
Comment options

@michalstrzelecki
Comment options

@michalstrzelecki
Comment options

@phryneas
Comment options

@mcdamo
Comment options

Comment options

You must be logged in to vote
3 replies
@kcrystalchen
Comment options

@VladyslavMartynov
Comment options

@ArtemBozhenko
Comment options

Comment options

You must be logged in to vote
2 replies
@phryneas
Comment options

@spacepolice10
Comment options

Comment options

You must be logged in to vote
21 replies
@panda919
Comment options

@adamhari
Comment options

@BenQoder
Comment options

@adamhari
Comment options

@panda919
Comment options

Comment options

You must be logged in to vote
3 replies
@BenQoder
Comment options

@Ebeldev
Comment options

@BenQoder
Comment options

Comment options

You must be logged in to vote
9 replies
@VictorPulzz
Comment options

@phryneas
Comment options

@VictorPulzz
Comment options

@phryneas
Comment options

@panda919
Comment options

Comment options

You must be logged in to vote
3 replies
@Athou
Comment options

@phryneas
Comment options

@spacepolice10
Comment options

Comment options

You must be logged in to vote
6 replies
@simenkid
Comment options

@CursedMun
Comment options

@simenkid
Comment options

@CursedMun
Comment options

@simenkid
Comment options

Comment options

You must be logged in to vote
12 replies
@AChristoff
Comment options

@phryneas
Comment options

@AChristoff
Comment options

@phryneas
Comment options

@spacepolice10
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@adamhari
Comment options

@BenQoder
Comment options

Comment options

You must be logged in to vote
4 replies
@Ahmedhamed77
Comment options

@gentlee
Comment options

@BenQoder
Comment options

@gentlee
Comment options

Comment options

You must be logged in to vote
15 replies
@panda919
Comment options

@gentlee
Comment options

@phryneas
Comment options

@gentlee
Comment options

@markerikson
Comment options

Comment options

You must be logged in to vote
2 replies
@The0racle
Comment options

@TheBoyWhoLivedd
Comment options

Comment options

You must be logged in to vote
6 replies
@panda919
Comment options

@markerikson
Comment options

@panda919
Comment options

@markerikson
Comment options

@panda919
Comment options

Comment options

You must be logged in to vote
5 replies
@firasrg
Comment options

@kiranNegiloni
Comment options

@firasrg
Comment options

@enrickdaltro
Comment options

@kiranNegiloni
Comment options

Comment options

You must be logged in to vote
1 reply
@markerikson
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@mlegghl
Comment options

Comment options

You must be logged in to vote
1 reply
@P1aster
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@issam-seghir
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@issam-seghir
Comment options

Comment options

You must be logged in to vote
3 replies
@markerikson
Comment options

@alex-mironov
Comment options

@markerikson
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet