I’m trying to get more than 100 records from Airtable in my React Native app. The API only gives 100 records by default, so I’ve used offset. But now I want to show these records in smaller groups when the user scrolls to the bottom of the FlatList.
The problem is all records are loading at once instead of in chunks. What am I doing wrong? How can I make it load records in smaller batches as the user scrolls?
I encountered a similar issue with Airtable pagination in React Native. The problem lies in how you’re managing the offset. Instead of incrementing by a fixed chunk size, update it based on the actual number of records fetched.
This approach ensures you’re only requesting new records each time. Also, consider implementing a check to stop fetching when you’ve reached the end of available records. This should resolve your chunking issue and provide a smoother scrolling experience.
I’ve dealt with this exact problem before. The key is to manage your state correctly and implement proper error handling. Here’s what worked for me:
Use a separate state for the total number of records, implement error handling in your API call, and add a check to stop fetching when all records are loaded. This strategy ensures that you’re not trying to fetch data continuously when there’s nothing left.
hey, seems ur offset update f’s messed up. try using: setCurrentOffset(prev => prev + newData.length). that way, only new records load when you scroll. lmk if it helps!