-
-
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] Fix undefined slot values #10934
Conversation
Deploy preview: https://deploy-preview-10934--material-ui-x.netlify.app/ |
const result = { ...defaultSlots }; | ||
Object.keys(overrides).forEach((key) => { | ||
const k = key as keyof typeof overrides; | ||
|
||
if (overrides[k] !== undefined) { | ||
result[k] = overrides[k] as any; | ||
} | ||
}); | ||
|
||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the fix! little bit less boilerplatey suggestion if you want:
const result = { ...defaultSlots }; | |
Object.keys(overrides).forEach((key) => { | |
const k = key as keyof typeof overrides; | |
if (overrides[k] !== undefined) { | |
result[k] = overrides[k] as any; | |
} | |
}); | |
return result; | |
return { | |
...defaultSlots, | |
...Object.fromEntries(Object.entries(overrides).filter([k] => k !== undefined)) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem equivalent. overrides
needs to be used. And the result needs to be set to the default slot unless an override is provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to be correct :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object.fromEntries(Object.entries(overrides).filter(fn)
is basically just a pickBy
pattern, so if you all have lodash or a similar util you could reduce this code even a little bit further
Closes #10933
Allow passing
undefined
as a slot value.