Skip to content

Instantly share code, notes, and snippets.

@fcgomes92
Last active May 11, 2017 17:08
Show Gist options
  • Save fcgomes92/71313abb41e084d0396b7eb7dfc8fb0b to your computer and use it in GitHub Desktop.
Save fcgomes92/71313abb41e084d0396b7eb7dfc8fb0b to your computer and use it in GitHub Desktop.
react-paginate (https://github.com/AdeleD/react-paginate) example
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
currentPage: 0,
pageCount: 10,
}
}
handlePageClick = (data) => {
this.setState({currentPage: data.selected});
};
handleOnClickButton = (goTo) => {
this.setState({
currentPage: goTo,
});
}
render() {
return (
<div>
<button onClick={()=>{this.handleOnClickButton(0)}}>Go to Page 1</button>
<button onClick={()=>{this.handleOnClickButton(1)}}>Go to Page 2</button>
<ReactPaginate
pageCount={this.state.pageCount}
pageRangeDisplayed={5}
marginPagesDisplayed={2}
onPageChange={this.handlePageClick}
forcePage={this.state.currentPage}
previousLabel={"previous"}
nextLabel={"next"}
breakLabel={<a href="">...</a>}
breakClassName={"break-me"}
containerClassName={"pagination"}
subContainerClassName={"pages pagination"}
activeClassName={"active"}/>
</div>);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment