-
-
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] Should not expose apiRef #1821
Comments
due to circle dependencies
Yes there is an inconsistency in that, originally I wanted to provide
If we expose api then the state of the api that was attached to current at the time we pass might be outdated if we use it outside a function or a useEffect. Hence why we use a ref. |
@dtassone Ok, so it would only help if we rename the property provided in the params from |
yes for consistency everywhere. |
@dtassone Are you saying that the |
The methods should be stable. But the state might be outdated if you use api in a useEffect for example as if there is a cycle then the ref won't be updated. |
Actually, based on #1103 (comment) maybe we should always exposes the apiRef but limits the methods available based on the version. We can implement this with module augmentation. The other use case for the apiRef with the DataGrid is customizations, I believe that the apiRef is required to bind the events correctly, for instance, with a custom pagination: https://master--material-ui-x.netlify.app/components/data-grid/components/#pagination import * as React from 'react';
import { makeStyles } from '@material-ui/styles';
import { DataGrid, useGridSlotComponentProps } from '@material-ui/data-grid';
import { useDemoData } from '@material-ui/x-grid-data-generator';
import Pagination from '@material-ui/lab/Pagination';
const useStyles = makeStyles({
root: {
display: 'flex',
},
});
function CustomPagination() {
const { state, apiRef } = useGridSlotComponentProps();
const classes = useStyles();
return (
<Pagination
className={classes.root}
color="primary"
count={state.pagination.pageCount}
page={state.pagination.page + 1}
onChange={(event, value) => apiRef.current.setPage(value - 1)}
/>
);
}
export default function CustomPaginationGrid() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 100,
maxColumns: 6,
});
return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid
pagination
pageSize={5}
components={{
Pagination: CustomPagination,
}}
{...data}
/>
</div>
);
} |
Current Behavior 😯
Developers can access apiRef in the community plan, while we document it a Pro plan feature.
Expected Behavior 🤔
Developers shouldn't be able to access apiRef in
DataGrid
, only inXGrid
.Steps to Reproduce 🕹
Steps:
Context 🔦
Saw it in #1820
As a side note, the current types and naming looks strange:
GridApiRef
instead of any?https://github.com/mui-org/material-ui-x/blob/fa346f0fbe3d9b9eea9bb403fe4675f544d6abf9/packages/grid/_modules_/grid/models/params/gridRowSelectedParams.ts#L15-L18
Why are naming the prop
api
if we don't provideGridApi
? Shouldn't it be calledapiRef
?Why expose apiRef when we could provide the api directly?
Your Environment 🌎
4.0.0-alpha.30
The text was updated successfully, but these errors were encountered: