-
-
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
[RFC] Change API state #190
Comments
Beside devexpress, are there many grids and components library using this approach of controlled vs uncontrolled? |
The initial proposal on the issue definitely work great when there are a limited number of states, like less than 5. For instance, TreeView has 2
I don't think that we should consider the problem with a lens on a data grid, but on how to handle the internal states of React components. (so be React focused, not grid focused). In any case, I think that we should lever break the uncontrolled/controlled pattern.
The approach you are suggesting sounds close to the "state reducer": e.g. https://github.com/downshift-js/downshift#statereducer or https://react-table.tanstack.com/docs/api/useTable#table-options. In this mode, the component seems to have:
This approach sounds promising to scale internal states :) |
@oliviertassinari Maybe we need to do some check at the |
@m4theushw Don't take my previous comments here too seriously. They were more ideas than actual recommendations that could work. Yeah, in the pagination, the imperative API is used to trigger the "on prop change" event. We could keep this, it's interesting if you want to use the apiRef to bind your own pagination component while controlling the prop in a parent of the data grid. So it makes me think that there are actually two completely different use cases for the apiRef, one to bind custom child components, and one to perform actions on the grid from the parent. |
An update:
|
Looking at the current shape of the API, it seems that we have an opportunity to explore a more intuitive and flexible API around how the different states can be handled. We have started to uncover this aspect in #133, where we talk about renaming
sortModel
tosortBy
. We have also uncovered some of the problems in #165 (comment) with the update columns method.Changes I would propose:
setSortModel
should warn when used without the uncontrollabe API:defaultSortModel
.defaultSortModel
prop to allow the uncontrollable API to function with the imperative APIsetSortModel
.defaultSortModel
prop could be supported, and equivalent to callingsetSortModel
.This gives us:
sortModel
: the controllable prop, will be used no matter what as a source of truth.defaultSortModel
: the uncontrollable prop, the state is hosted by the componentsetSortModel
: imperative API to update the uncontrollable mode, update the state hosted by the component. Throw or warn if the state is already controlled.onSortModelChange
: callback method used for the controllable mode.getSortModel
: imperative API to pull the state hosted by the component.Another corollary is that we should remove duplicated APIs, for instance: https://github.com/mui-org/material-ui-x/blob/91b05ee8b6cc9fb1beab96187fd4308d4b7b294b/packages/grid/x-grid-modules/src/models/colDef/colDef.ts#L56-L63 should be removed for simplicity and clarity.
In the documentation, I think that we should:
While in this demonstration, I take the "sortModel" state as an example, I think that we can apply the very same model to all the other states. In the core package, there is a useControlled() hook to normalize the behavior. Example of other states we can expose:
This should solve my concerns from #165 (comment). Exposing a
resetState
publicly doesn't feel right, not at all. From what I understand the boolean influences: caching and internal states. Caching should stay private and internal states should be exposed independently (columnsWidth
).The text was updated successfully, but these errors were encountered: