-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGrid] Inject extra props to customized components #641
Comments
You create a new Header component at every render so it rerender. You should put it outside the Table component or use React.useMemo |
@pat154 We have discussed this problem in mui/material-ui#21453, we are working on applying the conclusion to the whole codebase, we have migrated the Slider so far. In practice, it means that you will be able to do: <XGrid components={{ Header }} componentsProps={{ header: { searchTerm } }} /> The current API forces you to rely on the context: mui/material-ui#21453 (comment) as creating a new component at each keystroke inside a memo isn't viable (e.g loss of focus). |
I think the virtual DOM is smart enough to handle this. I believe it's the re-render at the
Thanks for this. Yeah I figured context might be a potential solution. I'll give it a try. |
Solved in #851. @dtassone I told you we could have made a dedicated PR only for the |
Firstly, big thanks for such a great library! This is my first time using it and it's a pleasure to use. I will most likely be moving to XGrid too as I have my eye on some roadmap features!
Current Behavior 😯
The Data Grid's
components.header
prop requires an argument of typeReact.FC
, as opposed to aReactElement
.This means that providing sharing state between the parent and the child always triggers a re-render. In my case, I have an input element and each time its value changes it loses focus.
Here is a basic example of what I am doing:
Expected Behaviour 🤔
I expect to be able to do something like provide a
ReactElement
as a component that would mean I can have a controlled input in the header that works as expected whilst still able to access shared state.Steps to Reproduce 🕹
https://codesandbox.io/s/compassionate-keldysh-z995k?file=/src/App.js
Steps:
Context 🔦
I'm trying to provide a search field in the header of the Data Grid to filter rows based on the string entered. Losing focus with each character entered results in an unacceptable user experience
Your Environment 🌎
The text was updated successfully, but these errors were encountered: