update sizePerPage through componentWillReceiveProps does not update select list
See original GitHub issueI 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:
- Created 7 years ago
- Comments:11 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
Merged #672. Released on
v2.5.1