erictooth / react-use-pagination Goto Github PK
View Code? Open in Web Editor NEWA React hook to help manage pagination state.
License: MIT License
A React hook to help manage pagination state.
License: MIT License
I initially wanted to skip having to write pagination logic myself so I wanted to use this hook but now I've reconsidered after attempting to implement this.
Passing initialPageSize
simply does not work, whatever I do the page size is always 3 for some reason. Additionally, calling setPageSize
does nothing either.
Furthermore, why is the page size state encapsulated inside the hook? This is not idiomatic at all, setPageSize
and initialPageSize
should not exist, that state (if it even is a state) should be at the implementation level and passed down React-like, not puppeteering a child state with parent state (very frustrating).
Why can't we just pass in the page size, current page and let the hook give back logic about previous, upcoming and total pages?! The library should help me implement my pagination, not control it.
I will write my own package now but I write this in hopes that 2.0 will have a more idiomatic and agnostic API.
sidenote: Try out an example on CodeSandbox does not work
I've glanced through the codebase and I think I may have found potential bug in the implementation of getEndIndex in a corner case when totalItems = 0
. The current implementation of getEndIndex would return a startIndex and endIndex of 0
as (totalItems - 1) = 1 - 1 = 0
. If users of this library rely on on using arr.slice to paginate their data (which seems like the obvious case), calling arr.slice(0,0)
evaluates []
and so the 1 item would not get rendered.
I've made a quick codesandbox to demonstrate the issue (and the fix) here. Hope I've been clear enough and please feel free to correct me if I'm wrong :)
I'm experiencing an issue where when using initialPageSize and even using setPageSize, the library is just using a completely different number to determine how many elements to display per page?
Failed to compile.
./node_modules/react-use-pagination/dist-module/react-use-pagination.mjs
Can't import the named export 'useCallback' from non EcmaScript module (only default export is available)
Hello, I'm a novice in react, and I encounter this error.
How can I solve this or what I am missing.
./node_modules/react-use-pagination/dist-module/react-use-pagination.mjs 52:85
Module parse failed: Unexpected token (52:85)
File was processed with these loaders:
return limitPageBounds(rootState.totalItems, action.pageSize)(action.nextPage ?? state);
|
| case "SET_TOTALITEMS":
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.