From d3216167641c52c3f8c727b6fa60082aefd44bf8 Mon Sep 17 00:00:00 2001 From: Daniel Cortes Date: Wed, 3 Jun 2020 20:10:31 -0400 Subject: [PATCH] Paginate no actualizaba sus props --- src/components/Paginate.jsx | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/components/Paginate.jsx b/src/components/Paginate.jsx index a91af0c..b49a4ec 100644 --- a/src/components/Paginate.jsx +++ b/src/components/Paginate.jsx @@ -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;