react-js-pagination icon indicating copy to clipboard operation
react-js-pagination copied to clipboard

Don't Receive pageNumber as arg by hooks

Open elibh159 opened this issue 4 years ago • 1 comments

Hi, I Used react-js-pagination in my function Component ,but onChange return undefined for me.

<Pagination activePage={pageNumber} itemsCountPerPage={pageSize} totalItemsCount={totalRows} pageRangeDisplayed={5} onChange={() => handleSearch(this)} /> Can you help me? Best Rigards

elibh159 avatar May 27 '20 05:05 elibh159

Hello,

I know this post is kinda old and you may have found a solution (by using the class component maybe). Still, I ran into the same issue and found a solution, I hope this will help some people! :) On an other way, since I'm still kinda a beginner at react concepts, I can't explain in details why this works... Would love to see someone improve this answer!!!

let [activePage, setActivePage] = useState(1);
// ...
return (
      <Pagination
        activePage={activePage}
        itemsCountPerPage={10}
        totalItemsCount={450}
        pageRangeDisplayed={5}
        onChange={(e: number) => setActivePage(e)}
      />
)

Rdyx avatar Jul 27 '20 22:07 Rdyx