wwwaiser / react-js-pagination

http://vayser.github.io/react-js-pagination
Creative Commons Zero v1.0 Universal
353 stars 95 forks source link

Don't Receive pageNumber as arg by hooks #107

Open elibh159 opened 4 years ago

elibh159 commented 4 years ago

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

Rdyx commented 4 years ago

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)}
      />
)