DEV Community

Discussion on: Pagination in Javascript and React, with a custom usePagination() hook

Collapse
 
jcubic profile image
Jakub T. Jankiewicz

Do you have a working demo? Does't it work with 1000 pages?

Collapse
 
damiisdandy profile image
damilola jerugba

The number of pages fully depend on the contentPerPage, the API route I used in the code only returns an array of 20 items so the maximum possible number of pages is either 1 or 20, with 3 contentPerPage it generated 7 pages

Here is a working demo => use-pagination.vercel.app/

Collapse
 
jcubic profile image
Jakub T. Jankiewicz • Edited

So it's not fully functional pagination. Just a simple demo.
Here is example how pagination should work (the code is in PHP but it's algorithm that can be rewritten in any language).
gist.github.com/bramus/5d8f2e0269e...

Also note that prev should be disabled when on first page.

Thread Thread
 
damiisdandy profile image
damilola jerugba

It's functional, I was referring to Typescript you were talking about types. There are many ways to implement pagination, this is just my way, and this will work for any language

Thread Thread
 
jcubic profile image
Jakub T. Jankiewicz • Edited

It's functional, I was referring to Typescript you were talking about types.

I don't quite understand what you write this above comment. I just mean that this is not fully implemented pagination, because it's missing fundamental features. So it can't be used in any real projects. You need to implement the thing yourself if you want to have something that is a full pagination. Also this will not work with any language because it's like half of the implementation.

Thread Thread
 
damiisdandy profile image
damilola jerugba • Edited

Sorry I thought I replied to another comment, could you list out these features, so I improve this React hook

Thread Thread
 
damiisdandy profile image
damilola jerugba

You are also free to make contributions to the repo

Thread Thread
 
jcubic profile image
Jakub T. Jankiewicz

Added two issues. I may contribute if the issue is not fixed when I will need pagination since I will need something like this in the near future for my application.

Thread Thread
 
damiisdandy profile image
damilola jerugba

👍🏽