'How to use firebase limits to paginate data
I'm used to php for backend, but I had to use firebase for this project cause of the realtime database...I am trying to paginate data loading. So far, I'm able to select the last 30 records using limitTolast(30). However, after this I need to select 30 older records after the last 30 I previously selected for when the user scrolls to the top...Please how do I achieve this
I already tried limtToLast(30).startAfter(30).
thank you.
UPDATE
I found a solution, using endBefore(lastkey).limitToLast(1).However, its still not the best. The issue with this is, I would want to limitToLast(10) but if I do that, it runs the query 10 times with the same value as lastkey which causes repetition in my app. Please how can I fix this...What I would want is either get the last 10 records before lastkey once or allow me change the lastkey each time the query runs. I hope this makes sense
my code looks like this
this.db.child('messages/'+chatid).endBefore(this.state.messages[this.state.messages.length - 1].key).limitToLast(10).once('child_added', snapshot => this.parse(snapshot))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
