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

[data grid] useGridApiRef returns RefObject, but DataGrid apiRef prop only accepts MutableRefObject #16194

Closed
ArmandRedgate opened this issue Jan 15, 2025 · 2 comments
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists

Comments

@ArmandRedgate
Copy link

ArmandRedgate commented Jan 15, 2025

Steps to reproduce

  1. Add the following code to a project running @mui/x-data-grid-pro v7.23.6 and TypeScript:
const apiRef = useGridApiRef();

<DataGridPro
  apiRef={apiRef}
  />

Current behavior

Currently, we get an error of the style

Type RefObject<GridApiPro> is not assignable to type MutableRefObject<GridApiPro>

when trying to pass an apiRef from useGridApiRef() to the DataGrid component.

This issue is likely related to #16135, but more specifically causes us to not be able to use the api at all without an ugly cast like

const apiRef = useGridApiRef() as MutableRefObject<GridApiPro>;

Or am I missing something? I couldn't find any documentation on how to register the apiRef if not like this.

Expected behavior

useGridApiRef() returning a MutableRef

Context

Our support key is 65425.

We use the apiRef for all sorts of stuff, including exportState(), setRowChildrenExpansion and others.

Your environment

npx @mui/envinfo
  System:
    OS: Windows 11 10.0.26100
  Binaries:
    Node: 22.6.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: Not Found
  Browsers:
    Chrome: Not Found
    Edge: Chromium (131.0.2903.146)
  npmPackages:
    @emotion/react:  11.10.6
    @emotion/styled:  11.10.6
    @mui/core-downloads-tracker:  6.4.0
    @mui/icons-material: 6.4.0 => 6.4.0
    @mui/material: 6.4.0 => 6.4.0
    @mui/private-theming:  6.4.0
    @mui/styled-engine:  6.4.0
    @mui/system:  6.4.0
    @mui/types:  7.2.21
    @mui/utils:  6.4.0
    @mui/x-data-grid:  7.23.6
    @mui/x-data-grid-pro: 7.23.6 => 7.23.6
    @mui/x-internals:  7.23.6
    @mui/x-license:  7.23.6
    @types/react: 18.3.18 => 18.3.18
    react: 18.3.1 => 18.3.1
    react-dom: 18.3.1 => 18.3.1
    typescript: 5.7.3 => 5.7.3

Search keywords: MutableRefObject apiRef GridApi

@ArmandRedgate ArmandRedgate added bug 🐛 Something doesn't work status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 15, 2025
@github-actions github-actions bot added the component: data grid This is the name of the generic UI component, not the React module! label Jan 15, 2025
@michelengelen
Copy link
Member

duplicate of #16000

Copy link

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@ArmandRedgate How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

@github-actions github-actions bot removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 15, 2025
@michelengelen michelengelen added the duplicate This issue or pull request already exists label Jan 15, 2025
@michelengelen michelengelen changed the title useGridApiRef returns RefObject, but DataGrid apiRef only accepts MutableRefObject [data grid] useGridApiRef returns RefObject, but DataGrid apiRef prop only accepts MutableRefObject Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants