Comments (3)
@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.
@davidalejandroaguilar for the same code, line to line, I'm getting this results. CSS not working.
from react-js-pagination.
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)
- Multiple React Instances HOT 1
- Multiple React Instances HOT 4
- How can i show the last page number?
- How can i show the last page number?
- How can i show the last page number?
- Npm install Fails HOT 1
- Don't Receive pageNumber as arg by hooks HOT 1
- How can I add simple href url? HOT 1
- No Way to Track Previous, Next, First, Last Page Events
- 2 instances of react detected because of react-js-pagination
- Cannot set both active and inactive classes
- Wrong URL in the Description
- Num of pages was incorrect HOT 1
- Is this package still maintained? HOT 2
- `pageRangeDisplayed` prop not working
- 2 high severity vulnerabilities HOT 2
- Is this project still maintained?
- Navigation does not work
- Change activePage but Paga not change
- Release 3.0.4? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-js-pagination.