GithubHelp home page GithubHelp logo

Comments (3)

davidalejandroaguilar avatar davidalejandroaguilar commented on May 26, 2024

@ilyasogonov, this component only generates markup based on the total items. There are only 3 required props: totalItemsCount, activePage and an onChange handler.

To display things, just have your component display things based on the activePage:

import React from 'react';
import Pagination from 'react-js-pagination';

const THINGS_PER_PAGE = 5;

export default class Things extends React.Component {
  state = {
    activePage: 1,
    things: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  };

  // Just set the active page on state on page change.
  handlePageChange = pageNumber => this.setState({ activePage: pageNumber });

  render() {
    // Things shown will be calculated based on active page.
    const indexOfLastThing = this.state.activePage * THINGS_PER_PAGE;
    const indexOfFirstThing = indexOfLastThing - THINGS_PER_PAGE;
    // For page 1, you will get things.slice(0, 5).
    // For page 2, you will get things.slice(5, 10).
    const thingsShown = this.state.things.slice(
      indexOfFirstThing,
      indexOfLastThing
    );

    // Then just show the things.
    return (
      <div>
        <ul>
          {thingsShown.map((thing, index) => (
            <li key={index}>{thing}</li>
          ))}
        </ul>

        <Pagination
          onChange={this.handlePageChange}
          activePage={this.state.activePage}
          totalItemsCount={this.state.things.length}
          itemsCountPerPage={5}
        />
      </div>
    );
  }
}

Ideally, you'd want to separate your component from containers, but this is just a mixed example for you to see the general idea.

from react-js-pagination.

Ruchit1395 avatar Ruchit1395 commented on May 26, 2024

@davidalejandroaguilar for the same code, line to line, I'm getting this results. CSS not working.
Screenshot from 2019-09-23 18-44-42

from react-js-pagination.

davidalejandroaguilar avatar davidalejandroaguilar commented on May 26, 2024

Hey there, as I said:

this component only generates markup

There's no CSS, you have to write that yourself. The first page of the package itself states it too:

The component comes with no built-in styles

from react-js-pagination.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.