react-bootstrap-table / react-bootstrap-table2

Next Generation of react-bootstrap-table
https://react-bootstrap-table.github.io/react-bootstrap-table2/
MIT License
1.27k stars 431 forks source link

Calling this.setState in onPageChanged callback breaks pagination #416

Open Ignalion opened 6 years ago

Ignalion commented 6 years ago

Calling this.setState in onPageChanged causes react render page on NEXT page changing that makes very weird behavior of the component.

I think root cause may be similar with onSelect one (and managing page # by hand as a workaround resolves the issue, like assign page in callback and pass page: in render)

class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {page: 1};
        this.onPageChange = this.onPageChange.bind(this);
    }

    onPageChange(page) {
        this.setState({page: page})
    }

    render() {
        const pagination = paginationFactory({
            // page: this.state.page,
            onPageChange: this.onPageChange,
        });
        console.log(this.state.selected);
        return (
        <BootstrapTable pagination={pagination} keyField='id' data={products} columns={columns}/>
        )
    }
}

Uncommenting line in render() resolves the issue but I think it would be good to fix this in component.

AllenFang commented 6 years ago

@Ignalion yes, u are right. i will consider to enhance this, so right now the workaround is you have to manage the page state manually.

fasenderos commented 3 years ago

Hi, @AllenFang any news on this? Is the workaround the only solution?