react-paginate icon indicating copy to clipboard operation
react-paginate copied to clipboard

forcePage is not working

Open arasan-goaugment opened this issue 2 years ago • 1 comments

I'm updating offset and page by using state and the offset is updating and the list shows the right content. But the active page is not updating properly as I triggered using forcePage option. But it not works. Items are displaying for 1st page as offset updated. But the button active is in some other prev active number due to this

function PaginatedItems({ items, props, page, itemOffset, updateOffset }) {
  const itemsPerPage = 10;

  const endOffset = itemOffset + itemsPerPage;

  const currentItems = items.slice(itemOffset, endOffset);
  const pageCount = Math.ceil(items.length / itemsPerPage);

  const handlePageClick = event => {
    const newOffset = (event.selected * itemsPerPage) % items.length;
    updateOffset(newOffset);

  };

  return (
    <>
      <LocationListItems
        locations={currentItems}
        showSidePanel={props.showSidePanel}
        hideSidePanel={props.hideSidePanel}
        scopes={props.scopes}
      />

        <ReactPaginate        
          onPageChange={handlePageClick}
          pageRangeDisplayed={5}
          pageCount={pageCount}
          forcePage={page}*      
          renderOnZeroPageCount={null}
        />
    </>
  );
}

Kindly help me to resolve this. thank in advance!

arasan-goaugment avatar Apr 11 '23 08:04 arasan-goaugment

Try -

const itemsPerPage = 10;

const currentItems = items.slice( itemsPerPage * 10 -10, itemsPerPage * 10)

Chandan9898Kumar avatar Apr 13 '23 18:04 Chandan9898Kumar