Table does not re-render when using redux for pageSize
See original GitHub issue// myTable.js
class MyTable extends React.Component {
render() {
return (
<div>
<h1>{this.props.pageSize}</h1>
<ReactTable
data={this.props.data} // not from redux
columns={this.props.columns} // not from redux
pageSize={this.props.pageSize} // from redux
/>
</div>
);
}
}
const mapStateToProps = state => ({ pageSize: state.pageSize });
export default connect(mapStateToProps, null)(MyTable);
// customTable.js
class CustomTable extends React.Component {
componentWillMount() {
this.props.loadData();
}
render() {
const columns = [...];
return (
<MyTable data={this.props.data} columns={columns} />
);
}
}
const mapStateToProps = state => ({ data: state.something });
const mapDispatchToProps = dispatch => ({ loadData: () => { dispatch(loadSomething()); } });
export default connect(mapStateToProps, mapDispatchToProps)(CustomTable);
Note that the value inside <h1>
changes, but the table does not re-render. If I map the pageSize
in CustomTable
and send it down as a normal prop, it works. The problem occurs when I have a container inside a container.
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (7 by maintainers)
Top Results From Across the Web
Table does not re-render when using redux for pageSize #502
myTable.js class MyTable extends React.Component { render() { return ( {this.props.pageSize}
Read more >Wanted To re-render table rows when state in redux changed
When you initialize state in constructor, data state is filled only once and will not be filled again when props change from Redux....
Read more >How to Make an Ant Design (AntD) Table in React JS
Table Props ; bordered: It is used to indicate whether to show all table borders or not. ; columns, Used to denote all...
Read more >How to Build a Custom Pagination Component in React
As I mentioned earlier, we'll be using the usePagination hook in our pagination component and we'll map over the returned range to render...
Read more >How to get better and easier state management with Redux ...
Learn through a simple project what state management improvements Redux Toolkit has to offer and whether it will be ideal for your project....
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 Free
Top 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
Had the same issue. solved it by adding a key to the child component to force rendering:
<ReactTable key={this.props.uniqueKey} ...
in you sandbox example adjust it as follows:
<ReactTable key={this.props.pageSize} ...
I see. I am happy with @redlock 's solution for now. Thanks!