r/reactjs • u/dance2die • Oct 01 '19
Beginner's Thread / Easy Questions (October 2019)
Previous threads can be found in the Wiki.
Got questions about React or anything else in its ecosystem? Stuck making progress on your app?
Ask away! Weβre a friendly bunch.
No question is too simple. π
π Want Help with your Code? π
- Improve your chances by putting a minimal example to either JSFiddle, Code Sandbox or StackBlitz.
- Describe what you want it to do, and things you've tried. Don't just post big blocks of code!
- Formatting Code wiki shows how to format code in this thread.
- Pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.
New to React?
Check out the sub's sidebar!
π Here are great, free resources! π
- Create React App
- Read the official Getting Started page on the docs.
- /u/acemarke's suggested resources for learning React
- Kent Dodd's Egghead.io course
- Tyler McGinnis' 2018 Guide
- Codecademy's React courses
- Scrimba's React Course
- Robin Wieruch's Road to React---
Any ideas/suggestions to improve this thread - feel free to comment here!
Finally, an ongoing thank you to all who post questions and those who answer them. We're a growing community and helping each other only strengthens it!
27
Upvotes
View all comments
Show parent comment
2
u/timmonsjg Oct 08 '19
I usually base this on the API.
Will you be fetching the entire collection of data all at once and paginating client-side? or will you be fetching data from the API every page?
If all at once, you can split it up into equal chunks (say 10 records / page) so if you have 242 records that's 25 pages. I'd probably do a nested array, but you could store it as an object.
But really, that's up to you. However you feel comfortable storing & manipulating the data.
If you are going to be fetching via API per page, you should have the API return the # of records initially. You'll do the same division and end up with 25 pagination buttons, each one calling the API with a query param of either
?page=3or?start=30&end=40.pagewould require the API to be aware of the pagination. Whilestartor a similar named param would just tell the API to give the records between 30 & 40.There's quite a few ways to approach pagination and it's not limited to these.