-
-
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] All selectors accept only apiRef
as first argument
#16198
base: master
Are you sure you want to change the base?
Conversation
Deploy preview: https://deploy-preview-16198--material-ui-x.netlify.app/ |
packages/x-data-grid-pro/src/components/GridDataSourceTreeDataGroupingCell.tsx
Outdated
Show resolved
Hide resolved
const loadingSelector = (state: GridStatePremium) => state.dataSource.loading[id] ?? false; | ||
const errorSelector = (state: GridStatePremium) => state.dataSource.errors[id]; | ||
const loadingSelector = (apiRefObject: React.RefObject<GridApiPremium>) => | ||
apiRefObject.current.state.dataSource.loading[id] ?? false; | ||
const errorSelector = (apiRefObject: React.RefObject<GridApiPremium>) => | ||
apiRefObject.current.state.dataSource.errors[id]; |
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.
These should probably be selectors with arguments.
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.
And rowSelector
below as well.
export const gridAggregationStateSelector = (state: GridStatePremium) => state.aggregation; | ||
export const gridAggregationStateSelector = (apiRef: React.RefObject<GridApiPremium>) => | ||
apiRef.current.state.aggregation; |
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.
I wonder if creating a createStateSelector
that pre-fetches apiRef.current.state
could be useful for readability.
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.
Creating a type like GridApiRef***
to make React.RefObject<GridApi***>
more compact could also be nice.
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.
I was about to do that, but have to resolve rendering issues first 🙂
const getPinnedColumns = React.useCallback<GridColumnPinningApi['getPinnedColumns']>(() => { | ||
return gridPinnedColumnsSelector(apiRef.current.state); | ||
return gridPinnedColumnsSelector(apiRef); | ||
}, [apiRef]); |
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.
I wonder if we should deprecate API methods that only call a selector.
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.
Yes please 👍🏻
Closes #11440