Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forcePage is not working #482

Open
arasan-goaugment opened this issue Apr 11, 2023 · 1 comment
Open

forcePage is not working #482

arasan-goaugment opened this issue Apr 11, 2023 · 1 comment

Comments

@arasan-goaugment
Copy link

arasan-goaugment commented Apr 11, 2023

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!

@Chandan9898Kumar
Copy link

Chandan9898Kumar commented Apr 13, 2023

Try -

const itemsPerPage = 10;

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants