-
-
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] Remove stateId argument from GridApi getState method #2141
Conversation
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.
95% of the time, the code written is
Then +1 for removing these 5% percent. For instance, it's not supported in https://react-redux.js.org/api/hooks#usestore.
-const filterState = apiRef.current.getState('filter');
+const filterState = apiRef.current.getState().filter;
or even:
-const filterState = apiRef.current.getState('filter');
+const filterState = filterGridStateSelector(apiRef.current.getState());
In general, I'm in favor of avoiding methods with separate behaviors like this one. getState: () => GridState
getSubState: <StateId extends keyof GridState>(stateId: StateId) => GridState[StateId] |
The API is public, I have added a new label. If we could update the description of the PR to document it, it would be perfect. Actually, are we confortable with making the whole state public? If we are not, we can make the method private. |
@oliviertassinari Yes, I would keep the state and this method public. For some parts of the state (e.g. |
For the stable version, we may want to make it private and only expose methods for the wanted substates. But for now I do agree that exposing it is simpler. |
OK, I guess that once the component is stable and we need to change one part of the state, then we can change the public |
@dtassone, we only have 2 calls of
getState
with astateId
, both in the same hook (useGridFilter
)Is this something we want to keep ?
95% of the time, the code written is
const page = apiRef.current.getState().page
instead ofconst page = apiRef.current.getState('page')
so I'm not sure the overhead is worth it here.But with this PR you can use the
stateId
with the correct typing without specifying it as a generic.@m4theushw the doc generation does not like the generic, I'm loosing the
StateId
definition here. Same thing for the type returned.It could be interesting to handle it. But I would more be in favor of droping the
stateId
param ongetState
(see above)