Paginate no actualizaba sus props
This commit is contained in:
@@ -22,22 +22,27 @@ const range = (from, to, step = 1) => {
|
||||
export default class Paginate extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
const {totalRecords = 0, pageLimit = 30, pageNeighbours = 0, currentPage = 1} = props;
|
||||
|
||||
this.pageLimit = typeof pageLimit === 'number' ? pageLimit : 30;
|
||||
this.totalRecords = typeof totalRecords === 'number' ? totalRecords : 0;
|
||||
this.pageNeighbours = typeof pageNeighbours === 'number' ? Math.max(0, Math.min(pageNeighbours, 2)) : 0;
|
||||
this.totalPages = Math.ceil(this.totalRecords / this.pageLimit);
|
||||
this.currentPage = typeof currentPage === 'number' ? currentPage : 1
|
||||
|
||||
this.state = {currentPage: this.currentPage};
|
||||
|
||||
this.loadProps = this.loadProps.bind(this);
|
||||
this.gotoPage = this.gotoPage.bind(this);
|
||||
this.handleClick = this.handleClick.bind(this);
|
||||
this.handleMoveLeft = this.handleMoveLeft.bind(this);
|
||||
this.handleMoveRight = this.handleMoveRight.bind(this);
|
||||
this.makePageLink = this.makePageLink.bind(this);
|
||||
this.fetchPageNumbers = this.fetchPageNumbers.bind(this);
|
||||
|
||||
this.loadProps();
|
||||
this.state = {currentPage: this.currentPage};
|
||||
}
|
||||
|
||||
loadProps() {
|
||||
const {totalRecords = 0, pageLimit = 30, pageNeighbours = 0, currentPage = 1} = this.props;
|
||||
|
||||
this.pageLimit = typeof pageLimit === 'number' ? pageLimit : 30;
|
||||
this.totalRecords = typeof totalRecords === 'number' ? totalRecords : 0;
|
||||
this.pageNeighbours = typeof pageNeighbours === 'number' ? Math.max(0, Math.min(pageNeighbours, 2)) : 0;
|
||||
this.totalPages = Math.ceil(this.totalRecords / this.pageLimit);
|
||||
this.currentPage = typeof currentPage === 'number' ? currentPage : 1
|
||||
}
|
||||
|
||||
gotoPage(page) {
|
||||
@@ -80,6 +85,8 @@ export default class Paginate extends Component {
|
||||
* {...x} => represents page neighbours
|
||||
*/
|
||||
fetchPageNumbers() {
|
||||
this.loadProps();
|
||||
|
||||
const totalPages = this.totalPages;
|
||||
const currentPage = this.state.currentPage;
|
||||
const pageNeighbours = this.pageNeighbours;
|
||||
|
||||
Reference in New Issue
Block a user