No rerender when updating data
See original GitHub issueI have a table of objects this.state.rows
to be rendered into an interactive data table that allows user to modify a certain field. When user clicks on a row, my custom dialog will show up and ask information. When user accepte it, I modify the data by this.setState({rows: newRows})
. The problem is no rerender occurs and the table remains unchanged.
Expected Behavior
The table updates as new data is pushed into.
Current Behavior
The table remains unchanged.
Steps to Reproduce (for bugs)
I simplify the step of showing dialog and mutating data. Just click the button “Change data” and all values of the first column will be appended “1”. https://codesandbox.io/s/yjv1o52o7z
Your Environment
Tech | Version |
---|---|
Material-UI | 3.9.3 |
MUI-datatables | 2.1.0 |
React | 16.8.6 |
browser | Firefox 66.0.5 64bits |
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
React re-render not showing updated state array
I am updating state in this manner as event handler function is not having access to latest state values. console.log(state) shows updated state ......
Read more >React re-renders guide: everything, all at once - Developer way
Re-render happens when React needs to update the app with some new data. Usually, this happens as a result of a user interacting...
Read more >Learn how to force react components to rerender without ...
A complete guide on component re-rendering. Here you will learn how to force react components to rerender without calling the set state.
Read more >When does React re-render components? - Felix Gerschau
React re-render explained. React is known for providing a fast user experience by only updating the parts of the UI that have changed....
Read more >How to Update Data Without Rerendering an Entire Grid in ...
Rerendering an entire Angular grid to updating a single record is very inefficient, and at times it can cause glitches due to the...
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
You can use it that way if you want, and actually, you may not even need to use
updateValue
, because the render function will be integrated with the table, so it should trigger the state updates you’re looking for.You can experiment with this example, that makes updates to the data directly in the “Delete” button: https://github.com/gregnb/mui-datatables/blob/master/examples/custom-action-columns/index.js. If you modify that code to change all the rows, it should also work.
Another experiment you can try is with the
customToolbar
which will let you add buttons and functions that impact the overall table data.@HeavenlyEntity, @perfectstrong It’s possible that your issue is the way you are attempting to update state. You may have an object reference issue. I describe that class of mistake here https://github.com/gregnb/mui-datatables/issues/1082.