In a table with inputs as cell, how to render only concerned rows instead of the entire table ?
When i change the value inside of a cell, the entire table gets rendered. How can i render only the row concerned by the change ?
4 Replies
genetic-orange•16mo ago
That's just how React works.
Another way of looking at this - when the data in this cell changes, how can the app be sure that all filters, sorting, pagination, etc. are updated predictably?
- Re-rendering is the only answer here.
This only becomes an actual issue if the performance of your app slows significantly. Only then is there a need to change up your approach.
- Limit rows, number of columns
- Use virtualisation, etc.
A good starting point on this topic is this article:
https://kentcdodds.com/blog/fix-the-slow-render-before-you-fix-the-re-render
Fix the slow render before you fix the re-render
How to start optimizing your React app renders
national-goldOP•16mo ago
Thanks for the tip, I will focus on the main problem which is not the performance of my table
fair-rose•16mo ago
I personally made a solution which only turns the cell into an input on click then focuses the input. A strategy like this may work well for your problem aswell.
national-goldOP•16mo ago
Interesting @mtti.gg , for now i made a solution that consists of putting a ref on the input element and triggering a focus event on that ref when the table state changes, but i will keep your solution in mind for a future refactoring