I am using react paginate for the pagination. While changing the number of items displayed per page, I am not able to change the selected page to 1. After hitting the API, the active page doesn't move to '1' index. I have to click on it.
<ReactPaginate
pageCount={parseInt(Math.ceil(pageCount / limit))}
pageRange={3}
marginPagesDisplayed={2}
onPageChange={handlePageChange}
containerClassName={
"relative z-0 inline-flex rounded-md shadow-sm -space-x-px"
}
previousLinkClassName={
"relative inline-flex items-center px-2 py-2 rounded-l-md border border-gray-300 bg-white text-sm font-medium "
}
breakClassName={
"relative inline-flex items-center px-4 py-2 border border-gray-300 bg-white text-sm font-medium text-gray-700"
}
nextLinkClassName={
"relative inline-flex items-center px-2 py-2 rounded-r-md border border-gray-300 bg-white text-sm font-medium "
}
pageClassName={
"bg-white border-gray-300 text-gray-500 hover:bg-gray-50 relative inline-flex items-center px-4 py-2 border text-sm font-medium"
}
disabledClassName={"text-gray-500 hover:bg-gray-50 cursor-none"}
activeClassName={
"z-10 bg-indigo-500 border-indigo-500 text-white relative inline-flex items-center px-4 py-2 border text-sm font-medium hover:text-indigo-500"
}
initialPage={0}
/>
If you pass your data as a prop into a sub component, this is how you do it
You pass a state variable called results which is an array
Then you use that array inside the component to present data
Whenever you pass a new results prop, we set itemOffset and currentPage as 0 to go to the first page.