Skip to content

Commit

Permalink
[docs] Enumerate all components that expect specific ref type
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjORbj committed Dec 16, 2021
1 parent 68ae67d commit 9aef06d
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions docs/src/pages/guides/migration-v4/migration-v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,24 +237,52 @@ This change affects almost all components where you're using the `component` pro

### Ref type specificity

For some components, you may get a type error when passing `ref`. In order to avoid the error, you should use a specific element type. For instance, `Card` does not accept the type of `ref` to be `HTMLElement`.
For some components, you may get a type error when passing `ref`. In order to avoid the error, you should use a specific element type. For example, `Card` expects the type of `ref` to be `HTMLDivElement`, and `ListItem` expects its `ref` type to be `HTMLLIElement`.

Here is an example:

```diff
import * as React from 'react';
import Card from '@mui/material/Card';
import ListItem from '@mui/material/ListItem';

export default function CardWithSpecificRefType() {
- const cardComponentRef = React.useRef<HTMLElement>(null);
+ const cardComponentRef = React.useRef<HTMLDivElement>(null);
export default function SpecificRefType() {
- const cardRef = React.useRef<HTMLElement>(null);
+ const cardRef = React.useRef<HTMLDivElement>(null);

- const listItemRef = React.useRef<HTMLElement>(null);
+ const listItemRef = React.useRef<HTMLLIElement>(null);
return (
<Card ref={cardComponentRef}></Card>
<div>
<Card ref={cardRef}></Card>
<ListItem ref={listItemRef}></ListItem>
</div>
);
}
```

The list of components that expect a specific element type is as follows:

##### `@mui/material`

- Accordion
- Alert
- Avatar
- ButtonGroup
- Card
- Dialog
- ImageList
- List
- Tabs
- Tab
- ToggleButton

##### `@mui/lab`

- TabPanel
- Timeline
- TreeItem

### Style library

The style library used by default in v5 is [`emotion`](https://github.com/emotion-js/emotion). While migrating from JSS to emotion, and if you are using JSS style overrides for your components (for example overrides created by `makeStyles`), you will need to take care of the CSS injection order. To do so, you need to have the `StyledEngineProvider` with the `injectFirst` option at the **top of your component tree**.
Expand Down

0 comments on commit 9aef06d

Please sign in to comment.