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.

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:closed
  • Created 6 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
redlockcommented, Sep 22, 2017

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} ...

0reactions
ghostcommented, Sep 22, 2017

I see. I am happy with @redlock 's solution for now. Thanks!

Read more comments on GitHub >

github_iconTop 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 >

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