-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[EuiSwitch] Not re-rendering on toggle in EuiDataGrid #4175
Comments
I put together a quick demo showing the state updates triggering a re-render https://codesandbox.io/s/hopeful-cherry-ot1im?file=/index.js However, I don't recommend setting up the state/data quite that way, as tying |
Okay, thank you! |
Okay I've managed to reproduce it: |
Thanks! Here's a quick walk-through of what's going on: Your setup stores whether the row is selected on the individual items' Conceptually, it's important to remember your
and the only way to get update a cell is let React know something in The best way to work with dynamic data in the datagrid is to provide it via Context. This can be done directly using React's createContext or by using a library such as recoil or MobX. Then the Our main datagrid example demonstrates this data access via context where it sets the context and then reads from it in I've forked your sandbox to show a modified, working demo of this:
Now when a switch is clicked, it calls |
Wow! Thank you very much, great answer. I also have a row-selection checkbox in the grid's I'll need a high performant state manager for future component anyway, so may as well migrate everything now, which would you recommend? |
Those work in your example because they are re-defined every time in the For performance, you'll need to avoiding changing any of the props listed in #3518 as they cause wider re-renders. Some work on the virtualization (#4170) is shortening that list, but at the moment it should be representative. For testing, I throw a For performant state management - both for EuiDataGrid and any larger React application - you'll need something that ties data updates to specific components. MobX does this with observers while Recoil uses atoms to maintain separation. Both of those are good, but are very different to work with so it's up to your preference. There are other state libraries too, just look for the ability to subscribe components to individual pieces of state. |
Ah, makes sense. Thank you so much for your help! I have a lot of refactoring to do... |
EuiSwitch
es in a column (not leading/trailing) of anEuiDataGrid
do not re-render on toggle.The
EuiSwitch
I click on is not re-rendered until I go to another page and back.I added
console.log
s and clicking definitely triggers therender
function of theEuiDataGrid
and the callback of theEuiSwitch
.The state of the
EuiSwitch
is stored in theEuiDataGrid
and is rendered in therenderCellValue
function like so:I was looking at the implementation of EuiSwitch and I don't understand how it updates its own checked state, I expected something closer to
The project I'm working on is my first experience with React, so I welcome any suggestions/explanations :)
The text was updated successfully, but these errors were encountered: