question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

update sizePerPage through componentWillReceiveProps does not update select list

See original GitHub issue

I have the following table.

SizePerPage defaults to 10 but should be updated through componentWillReceiveProps.

If this happens and options.sizePerTable becomes say 30, 30 rows are indeed rendered, but the sizePerPage widget still shows 10. [of interest: on the next render, by opening another component and coming back to this one, the widget updates to the desired 30]

Is there anything obvious I am overlooking here? Do I pass the correct parameters?

export default class PaginationTable extends React.Component {
  constructor (props) {
    super(props);
    this.state = {
      options: {
        page: this.props.data.options._page || 1,  // which page you want to show as default
        onPageChange: this.props.onPageChange,
        onFilterChange: this.props.onFilterChange,
        onRowClick: this.props.onRowClick,
        sizePerPage: this.props.data.options._pageSize || 10,  // which size per page you want to locate as default
        pageStartIndex: 1, // where to start counting the pages
        paginationSize: 9,  // the pagination bar size.
        prePage: '<', // Previous page button text
        nextPage: '>', // Next page button text
        firstPage: '<<', // First page button text
        lastPage: '>>' // Last page button text
      }
    };
  }

  componentWillReceiveProps (newProps) {
    const sizePerPage = _.get(newProps, 'data.options._pageSize');
    if (sizePerPage !== this.props.data.options._pageSize) {
      this.setState({
        options: _.assign({}, this.state.options, {sizePerPage})
      });
    }
  }

  render () {
    return (
      <BootstrapTable
        data={this.props.data.data}
        fetchInfo={{ dataTotalSize: this.props.data.numRows }}
        remote={true}
        pagination={true}
        options={this.state.options}
        striped={true}
        hover={true}
        selectRow={this.props.selectRow}>
        {this.props.children}
      </BootstrapTable>
    );
  }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
doshisunnycommented, Aug 30, 2016

@AllenFang I am having also same issue and I tested with Raffiki solution. And adding sizePerPage:nextProps.options.sizePerPage resolves the issue also for me. this seems like missing from set state. Let me know if you want me to make pull request.

0reactions
AllenFangcommented, Sep 3, 2016

Merged #672. Released on v2.5.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

React componentWillReceiveProps not updating state
I've got this React parent component here. The children components at this point are just returning dropdown menus.
Read more >
View Raw - UNPKG
keepSizePerPageState`, enable it will make size per page dropdown keep open if ... Fix update sizePerPage through componentWillReceiveProps does not update ...
Read more >
React.Component
An update can be caused by changes to props or state. These methods are called in the following order when a component is...
Read more >
Using Derived State in React - DigitalOcean
As you can see, componentWillReceiveProps is often used to update the component's state. It can also have side effects, such as the call...
Read more >
Warning: componentWillMount has been Renamed, and is not ...
Starting in React version 16.3, the following component lifecycle methods are being phased out. componentWillMount; componentWillReceiveProps ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found