"ReactPaginate's Dual Paginator feature for both Top and Bottom navigation

Dealing with Pagination:

const CarsSection = () => {
  const itemsPerPage = 8;
  const [itemOffset, setItemOffset] = useState(0);
  const endOffset = itemOffset + itemsPerPage;
  const currentItems = carsData.slice(itemOffset, endOffset);
  const pageCount = Math.ceil(carsData.length / itemsPerPage);

  const handlePageClick = (event) => {
    const newOffset = (event.selected * itemsPerPage) % carsData.length;
    setItemOffset(newOffset);
  };


  return (
    <>
        <PaginationTop>
          <ReactPaginate
            nextLabel=">"
            onPageChange={handlePageClick}
            pageRangeDisplayed={3}
            marginPagesDisplayed={2}
            pageCount={pageCount}
            previousLabel="<"
            pageClassName="page-item"
            pageLinkClassName="page-link"
            previousClassName="page-item"
            previousLinkClassName="page-link"
            nextClassName="page-item"
            nextLinkClassName="page-link"
            breakLabel="..."
            breakClassName="page-item"
            breakLinkClassName="page-link"
            containerClassName="pagination"
            activeClassName="active"
            renderOnZeroPageCount={null}
          />
        </PaginationTop>
        <CarsContainer>
          <Items currentItems={currentItems} />
        </CarsContainer>

//Same <ReactPaginate /> (code is too big couldn't put it down)//


    </>
  );
};

export default CarsSection;

Currently implementing two separate paginators at top and bottom. Issue arises when clicking on bottom paginator doesn't update the state for the top paginator.

Attempted using forcePage={itemOffset}, but results were not as expected...

Answer №1

According to this npm package:

forcePage - This Number parameter allows you to manually set the selected page using a parent prop, which is helpful for controlling the page from your application state.

const [currentPage, setCurrentPage] = useState(0);
<ReactPaginate
  forcePage={currentPage}
  onPageChange={newPage => setCurrentPage(newPage)}
  ...
/>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transform a JavaScript object array into a collection of individual values

Given a list of objects structured like this, I am looking to transform it into a list of values based on their corresponding IDs. Original = [ {id: 1, value: 12.2494, time: "00:00:00.14"}, {id: 1, value: 4.5141, time: "00:00:01.138"}, {id: 1, ...

Shade the tag when the checkbox is marked

Is it possible to change the color of a label without using javascript when the associated checkbox is checked? ...

Baffled by the data visualization produced by Google Chart using information from

Perhaps I'm being a bit ambitious, but I managed to create a basic Chart using GoogleCharts. The problem is that I have to input the values manually, but I want to retrieve them from the Database. I know JSON can accomplish this, but I've spent f ...

Ensuring Form Security with JQuery Validation

Hello everyone, I'm currently working on a login form with jQuery validation to ensure that the user ID and password entered are valid. So far, this is what I have implemented: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/l ...

Having difficulty updating a web page while utilizing setInterval() and passing a function that utilizes document.write to display JavaScript content on the page

At the core of my issue lies a blank HTML page that incorporates a JavaScript file, with the following code in the JavaScript file: function doIt() { document.writeln("asdf"); } // Alternatively, you can use setTimeout setInterval("doIt()", 5000); Upon ...

The assertion that 'd3Ctrl' is not a valid function, but instead is undefined

Although several people have raised the same issue before and I've attempted their solutions, I still can't seem to resolve it. My problem involves using d3, but I keep encountering this error: app.js var app = angular.module('myApp', ...

Executing a function with a click, then undoing it with a second click

My goal is to trigger an animation that involves text sliding off the screen only when the burger icon is clicked, rather than loading immediately upon refreshing the page. The desired behavior includes activating the function on the initial click and then ...

Ways to minimize the json data size

let c=[ { "eventid": 29096475, "eventname": "Fortuna Dusseldorf v Stuttgart", "opendate": "2019-02-09T18:30:00.000Z", "eventtypeid": 1, "eventtypename": "Soccer", "marketname": "Match Odds", "ma ...

dc.js selects a chart that has already been rendered

I am attempting to manually adjust the width of a pie chart that has already been generated. The chart is constructed and displayed using an angular factory and directive, and I want to access this chart from a controller. Is there a method similar to var ...

Highcharts React does offer a Gauge Series, but it should be noted that this is different from the Solid Gauge

Explore this link for a sample of a speedometer chart using Highcharts Looking to integrate this chart into a React project. Managed to implement a Solid Gauge, but struggling with the Gauge Series. Check out the provided Sandbox for a Solid Gauge exampl ...

Tips for converting PDF files to images or reducing PDF file size using JavaScript

In my web application built with Next.js, I have a requirement where users can upload PDF files. However, I need to compress these files to a smaller size (e.g. 1MB). Despite searching extensively, I haven't found a satisfactory solution that meets my ...

Exploring the potential of utilizing records within deepstream.io

Lately, I've been delving into the world of records and I find myself pondering on the practical limitations when it comes to the size of a json structure. Is there a recommended maximum length? Can you store an entire chat history as an (anonymous) r ...

The Highchart chart is currently experiencing compatibility issues on both Chrome and Firefox

After designing a Highchart for my report, I encountered an issue where it wasn't displaying on Chrome and Firefox browsers. However, the chart was visible when using IE after enabling ActiveX. Can someone provide insight into why this discrepancy occ ...

Exploring data that is nested within its parent

I'm struggling to understand the concept of Nested selections or how to apply it to my specific situation. Here is an example of the JSON data format I am working with: { 'name': 'root' 'children': [ { &ap ...

Addressing Image Issues in CSS Grid

I'm struggling to position two images in different sections of a grid layout without overlapping them. I've attempted referencing the images by both their class and id, but they continue to occupy the same grid space. Referencing the images by ...

Converting a string array to an array object in JavaScript: A step-by-step guide

My task involves extracting an array from a string and manipulating its objects. var arrayString = "[{'name': 'Ruwaida Abdo'}, {'name': 'Najlaa Saadi'}]"; This scenario arises when working with a JSON file where ce ...

What is the best way to add a background image to a div using react?

My images folder contains 2 images. See the code snippet below from App.js: import "./styles.css"; import nf_logo from "./images/netflix_logo.png"; import nf_bg from "./images/netflix_bg.jpg;; const divStyle = { backgroundImag ...

After the rendering of the HTML, the value of the jQuery input does not change

Here we have a function that loads HTML onto the form class in a file. The quest[q] locates the appropriate HTML template to load from an array of templates. The HTML being loaded contains an input with an id of "p". I am attempting to set the value of th ...

What are the steps involved in generating and implementing dynamic hierarchical JSON data structures?

I am currently creating a dynamic diagram using d3.js that incorporates hierarchical data. The goal is to make it interactive so that users can manipulate the hierarchy by adding or removing data values and children. I'm wondering if there is a way to ...

Issues with incorrect sizing in Safari when using rem units alongside animations

UPDATE: After further testing, it appears that the code functions correctly within the SO snippet view. To replicate the issue, please copy the code and save it locally. UPDATE 2: Odd behavior detected. Refer to this gist and video for more information. ...