Skip to content
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] Refactor: make all selectors accept the same argument #11440

Open
Tracked by #13188
romgrk opened this issue Dec 17, 2023 · 0 comments
Open
Tracked by #13188

[datagrid] Refactor: make all selectors accept the same argument #11440

romgrk opened this issue Dec 17, 2023 · 0 comments
Labels
breaking change component: data grid This is the name of the generic UI component, not the React module! v8.x

Comments

@romgrk
Copy link
Contributor

romgrk commented Dec 17, 2023

Currently, grid selectors either accept the apiRef, or the apiRef.current.state, so calling them directly can look like this:

const a = gridColumnsStateSelector(apiRef.current.state)
const b = gridColumnFieldsSelector(apiRef)

It is inconsistent. This also mean we can't evolve a selector from unmemoized to memoized:

// From this form:
const gridXxxxSelector = (state: GridState) => state.xxxx
// To this form:
const gridXxxxSelector = createSelectorMemoized(yyyySelector, (y) => y.x)

Because it would be a breaking change. We should stick to a single way to pass the state, and it should be apiRef for simplicity & DX. We could preserve passing apiRef.current.state for compatibility, but move our codebase & the docs to the new style. This could also be done as a breaking change if we want to cleanup the code, but as we're already releasing a lot of breaking changes I'm not sure it would be a good time right now.

Somewhat related, right now the selectors show a warning message if the apiRef.current.state is passed but the selector is memoized, because selectors use the apiRef.current.instanceId as a cache key. We should not display warning messages, either accept the arguments or reject them. Or also just add the instanceId on the state instead of skipping memoization & warning the user :|

Search keywords:

@romgrk romgrk added the component: data grid This is the name of the generic UI component, not the React module! label Dec 17, 2023
@github-project-automation github-project-automation bot moved this to 🆕 Needs refinement in MUI X Data Grid Jan 2, 2024
@cherniavskii cherniavskii moved this from 🆕 Needs refinement to 🔖 Ready in MUI X Data Grid Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: data grid This is the name of the generic UI component, not the React module! v8.x
Projects
Status: 🔖 Ready
Development

No branches or pull requests

3 participants